How to resample time vector data matlab -
i have resample following cell array:
dates = '2004-09-02 06:00:00' '2004-09-02 07:30:00' '2004-09-02 12:00:00' '2004-09-02 18:00:00' '2004-09-02 19:30:00' '2004-09-03 00:00:00' '2004-09-03 05:30:00' '2004-09-03 06:00:00'
following irregular spacing, e.g. between 1st , 2nd rows there 5 readings, while between 2 , 3rd there 10. number of intermediates 'readings' stored in vector 'v'. so, need new vector intermediate dates/times in same format @ dates.
edit:
there's 1h30min = 90min between first 2 readings in list. 5 intervals b/w them amounts 90 mins / 5 = 18 mins. insert 5 'readings' between (1) , (2), each separated 18mins. need dates.
any ideas? thanks!
you can interpolate serial dates interp1()
:
% inputs dates = [ '2004-09-02 06:00:00' '2004-09-02 07:30:00' '2004-09-02 12:00:00' '2004-09-02 18:00:00' '2004-09-02 19:30:00' '2004-09-03 00:00:00' '2004-09-03 05:30:00' '2004-09-03 06:00:00']; v = [5 4 3 2 4 5 3]; % serial dates serdates = datenum(dates,'yyyy-mm-dd hh:mm:ss'); % interpolate x = cumsum([1 v]); resampled = interp1(x, serdates, x(1):x(end))';
the result:
datestr(resampled) ans = 02-sep-2004 06:00:00 02-sep-2004 06:18:00 02-sep-2004 06:36:00 02-sep-2004 06:54:00 02-sep-2004 07:12:00 02-sep-2004 07:30:00 02-sep-2004 08:37:30 02-sep-2004 09:45:00 02-sep-2004 10:52:30 02-sep-2004 12:00:00 02-sep-2004 14:00:00 02-sep-2004 16:00:00 02-sep-2004 18:00:00 02-sep-2004 18:45:00 02-sep-2004 19:30:00 02-sep-2004 20:37:30 02-sep-2004 21:45:00 02-sep-2004 22:52:30 03-sep-2004 00:00:00 03-sep-2004 01:06:00 03-sep-2004 02:12:00 03-sep-2004 03:18:00 03-sep-2004 04:24:00 03-sep-2004 05:30:00 03-sep-2004 05:40:00 03-sep-2004 05:50:00 03-sep-2004 06:00:00
Comments
Post a Comment