使用 MATLAB (R2015b) 我有A
一个 4000x3 矩阵的时间序列。下面是一个示例,其中第一列是串行时间(这里是从 13:56:37 到 14:25:09),第二列和第三列是测量值:
1.0e+05 *
7.366965809837962 0.000082000000000 0.062000000000000
7.366965810300925 0.000082500000000 0.013000000000000
7.366965836689815 0.000083000000000 0.040000000000000
7.366965857291667 0.000085000000000 0.013000000000000
7.366965875810186 0.000086000000000 0.010000000000000
7.366965876851851 0.000086000000000 0.020000000000000
7.366965889351852 0.000087000000000 0.015000000000000
7.366965892245370 0.000087000000000 0.016000000000000
7.366965896875000 0.000087000000000 0.004000000000000
7.366965897337963 0.000087500000000 0.050000000000000
7.366965901967592 0.000087500000000 0.002000000000000
7.366965906018518 0.000093000000000 0.010000000000000
7.366965907060185 0.000093000000000 0.010000000000000
7.366965928587963 0.000092000000000 0.010000000000000
7.366965962268518 0.000091500000000 0.030000000000000
7.366965973263889 0.000092000000000 0.001000000000000
7.366965974768519 0.000092000000000 0.050000000000000
7.366965982060186 0.000090000000000 0.010000000000000
7.366965993402777 0.000090000000000 0.090000000000000
7.366966007986111 0.000090000000000 0.043330000000000
如何每五分钟(而不是每个事件)计算第二和第三列的平均值?因此,对于前 5 分钟 13:55:00 - 14:00:00,我们应该得到中间列的平均值 8.225 和右列的平均值 3750,例如:
13:55:00 8.225 3750
14:00:00 8.4 2650
我尝试过但没有成功,因此非常感谢任何帮助。
我认为这可以帮助你
%Inital reference position
pos=1;
%Counter
count=1;
for i=2:20
%Elapsed seconds since the reference position
elapsed_seconds=etime(datevec(a(i,1)),datevec(a(pos,1)));
if elapsed_seconds>5*60 %Calculate means if larger than 5 minutes
matrix(count,1)=a(pos,1);
matrix(count,2)=mean(a(pos:(i-1),2));
matrix(count,3)=mean(a(pos:(i-1),3));
count=count+1; %Update counter
pos=i; %Update reference position
end
end
matrix
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句