假设如果我每隔2分钟收集一次数据并想计算15分钟的平均值,考虑到2不会“进入” 15,我该如何在matlab中做到这一点?
假设我有这样的数据集
time = {'2009-01-15 00:02';'2009-01-15 00:04';...
'2009-01-15 00:06';'2009-01-15 00:08';'2009-01-15 00:12';...
'2009-01-15 00:14';'2009-01-15 00:16';...
'2009-01-15 00:18';'2009-01-15 00:20';...
'2009-01-15 00:22';'2009-01-15 00:24';'2009-01-15 00:26';...
'2009-01-15 00:28';'2009-01-15 00:30'};
dat = [1,3,1,4,2,5,6,1,3,1,4,2,5,6];
我将如何计算15分钟的平均值?
代码-
% Edit this based on your choice of starting from 00:00 or from the first entry
start_from_0000 = false;
% Performing Code
datenum_mins = datenum(time)*24*60;
if start_from_0000
start1 = floor(datenum(time(1)))*24*60;
ind_15min_periods = floor((datenum_mins - start1)./15)+1;
else
ind_15min_periods = floor((datenum_mins - datenum_mins(1))./15)+1;
end
mean_dat = zeros(max(ind_15min_periods),1);
for c1 = 1:max(ind_15min_periods)
mean_dat(c1) = mean(dat(ind_15min_periods==c1));
end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句