P.S. I know the waitbar slows it down even more. I use it while programming to get an idea of the speed...
speed up process of importing data from one vector to another
1 view (last 30 days)
Show older comments
Marc Jakobi
on 10 Dec 2013
Commented: Marc Jakobi
on 10 Dec 2013
Hi. I have a vector with a timestamp (using Matlab numbers) which I want to import to another vector with a resolution of one second. The second vector is extremely large (since it contains a space for every second of the year 2011).
Here is my code so far: timestNUM: the original timestamp (containing Matlab datenums) VLeist: the original measurements
StartNUM = datenum(['01/01/2011',' 00:00:00'],'dd/mm/yyyy HH:MM:SS');
EndNUM = datenum(['31/12/2011',' 23:59:59'],'dd/mm/yyyy HH:MM:SS');
Step = 1./86400; %One second
timestSecNUM = (StartNUM:Step:EndNUM)';
VLeist_m = 10000.*ones(length(timestSecNUM),1); %the new vector which is to be filled
%the filling of the vector:
Progress = waitbar(0,'Filling high resolution vector with original values...');
x = length(VLeist); ct = 0;
for i = 1:x
k = find(timestSecNUM == timestNUM(i));
VLeist_m(k) = VLeist(i);
ct = ct + 1;
waitbar(ct./x);
end
The problem with my method is that the vectors tiemstNUM and VLeist have a length of over 500000. Because the resolution is supposed to be one second, the vectors VLeist_m and timestSecNUM each have a length of over 31.5 million!
You can imagine how long my loop takes... Any suggestions on how to speed up the process?
Thanks in advance!
Accepted Answer
Walter Roberson
on 10 Dec 2013
Have you tried ismember() in its two-output version?
[tf, idx] = ismember(timestNUM, timestSecNUM);
VLeist_m(idx(tf)) = VLeist(tf);
No loop.
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!