improving data averaging in a loop (is too slow)
Show older comments
Good Morning, I have a series of data in a matrix and i want to take the average data every
SECONDS_SCAN = (number of seconds),
"remembering" the deltaT of time between the data.I tried with this double loop, where I used variables like the ones given in the examples, but much larger. The script is:
deltaT=zeros(size(TIME(:,1)));
D=zeros(size(ATOT));
for k=1:length(ATOT(1,:))
i=1;
for j=1:(length(TIME(:,1)))
if etime(TIME(j,:),TIME(i,:))>=SECONDS_SCAN
deltaT(j,1)=etime(TIME(j,:),TIME(i,:));
%R(j,1)=1;
D(j,k)=nanmean(ATOT(i:j,k));
i=j+1;
end
end
end
The variables are:
SECONDS_SCAN = (number of seconds)
TIME=
2007 4 6 13 50 33
2007 4 6 13 50 36
2007 4 6 13 50 38
2007 4 6 13 50 40
2007 4 6 13 50 42
ATOT=
30.2000 30.2000 29.9000 29.9000 29.9000 29.9000 29.4000
30.2000 29.9000 29.9000 29.7000 29.7000 29.4000 29.9000
29.9000 29.9000 29.9000 29.9000 29.7000 29.7000 29.4000
30.4000 30.2000 29.9000 29.7000 29.4000 29.9000 29.7000
30.2000 29.9000 29.9000 29.7000 29.7000 29.4000 29.9000
I also would like to reduce the matrix D, because in the final one i have plenty of "0": I'm just able to do it AFTER having done the averaging.
I'm quite new to Matlab, but I need this data processing program, and I don't know what to do to make it faster, because with my large data files, that implicates hours of time to be done.
Thanks
2 Comments
Sean de Wolski
on 27 Feb 2015
I'm not clear on exactly what yuou want. What is SECONDS_SCAN what are the columns of TIME what does ATOT have to do with anything?
There is a likely a very fast and elegant way to do this with histcounts/histc and accumarray, but I'm not clear on what the inputs would be.
ludvikjahn
on 27 Feb 2015
Accepted Answer
More Answers (0)
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!