Question

Say if I have data collected at 2 minute intervals and wanted to calculate 15 minute averages, how would I do this in matlab, considering that 2 does not 'go into' 15?

Say if I had a data set like so

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];

how would I calculate the 15 min average?

Was it helpful?

Solution

Code -

% 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top