improving data averaging in a loop (is too slow)
이전 댓글 표시
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
Sean de Wolski
2015년 2월 27일
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
2015년 2월 27일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!