I am dealing with big amount of data where the for loop takes a long time to process.
tic
% index_tracks_matching_temp is a vector of 60 million (1*60m), also track_length_dns is 150k long
index_points_matching_temp=index_points_matching;
for i=1:1000 % just first 100 tracks %% or for i=1:track_length_DNS
mycell_track_index{i,1}=index_tracks_matching_temp(1:track_length_DNS(i));
mycell_points_index{i,1}=index_points_matching_temp(1:track_length_DNS(i));
index_tracks_matching_temp(1:track_length_DNS(i))=[];
index_points_matching_temp(1:track_length_DNS(i))=[];
end
clear index_tracks_matching_temp index_tracks_matching_temp
toc
% processing for i=1000 takes 30 seconds and I need to process up to 500k that's why i need a different way to do it. I always used loops so im not sure about other ways to do it

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Apr. 2021

0 Stimmen

If I read the code correctly, then
numused = sum(track_length_DNS);
mycell_tracks_index = mat2cell(index_tracks_matching(1:numused), 1, track_length_DNS);
mycell_points_index = mat2cell(index_points_matching(1:numused), 1, track_length_DNS);
with no loop.

1 Kommentar

Tarek
Tarek am 13 Apr. 2021
thanks, Mat2cell function is perfect, I did not know about it before.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 13 Apr. 2021

Kommentiert:

am 13 Apr. 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by