3

I have measured a handful of variables in 30 minute intervals. Time stamps are available in datevec or datenum format. I want to calculate ...

a) ... daily averages and
b) ... average values at time x, e.g. temperature at 11:30, temperature at 12:00, etc. averaged over my whole dataset.

While this is, more or less, easily done with loops, I wonder if there is an easier / more convenient way to work with time-series, since this is a quite basic task after all?

/edit 1: As per request: click me for sample data

Fred S
  • 1,421
  • 6
  • 21
  • 37
  • 2
    I can provide a solution with `accumarray()` if you post some example data. – Oleg Jun 10 '13 at 20:27
  • I hope 100 measurements are enough: [click me for sample data](https://dl.dropboxusercontent.com/u/9437411/sampledata_ts.mat) – Fred S Jun 10 '13 at 20:31

1 Answers1

6

Considering that datevec() output is stored in tvec and data in x, group with unique(...,'rows') and accumulate with accumarray():

% Group by day
[unDates, ~, subs] = unique(tvec(:,1:3),'rows');

% Accumulate by day
[unDates accumarray(subs, x, [], @mean)]

% Similarly by hour
[unHours, ~, subs] = unique(tvec(:,4:5),'rows');
[unHours accumarray(subs, x, [], @mean)]
Oleg
  • 10,406
  • 3
  • 29
  • 57