假设我是否每隔2分钟收集数据并想计算15分钟的平均值,我将如何在matlab中执行此操作,考虑到2不会进入' 15?
说我是否有这样的数据集
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分钟的平均值?
答案 0 :(得分:1)
代码 -
% 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