How to populate complete time series with incomplete data

3 views (last 30 days)
I have time series data with skipped periods that I wish to place onto a complete time stamp array. Rather than mm/dd format I have 'year' 'day of year (DOY)' and 'HHMM' 'Var1' like so
data=
2015 59 30 -31.42
2015 59 100 -31.21
2015 59 130 -31.06
2015 59 700 -30.9
2015 59 730 -30.38
2015 59 800 -30.07
2015 59 830 -29.83
2015 59 900 -29.69
2015 59 930 -29.53
2015 59 1000 -29.27
2015 59 1500 -26.11
2015 59 1530 -26.09
By comparing 'data' with a complete time series array 'full', I can get an 'index' value for missing periods, but I can't figure out how to bring the data (Var 1 etc) with it.
index = ismember( full(:, 3), data(:,3));
Only how to overlay the full set with NaN values for missing indices
fullindex = [index index index];
full(~fullindex)=nan;
Similar to this post http://www.mathworks.com/matlabcentral/answers/175089#answer_166928 but I can't use the 'datenum()' approach since I have DOY and different time stamps.

Accepted Answer

Chad Greene
Chad Greene on 21 Jan 2016
You can get a vector in datenum format by
t = datenum(YEAR,1,DOY);
and if you'd like you can get t into year, month, day by
[year,month,day] = datevec(t);
  1 Comment
Colin Edgar
Colin Edgar on 21 Jan 2016
You have no idea how helpful this is, thanks! I didn't understand datenum() at all apparently.
I see that if the HHMM is split up that I can have it all:
t = datenum(YEAR,1,DOY,HOUR,MINUTE,1);

Sign in to comment.

More Answers (1)

Colin Edgar
Colin Edgar on 21 Jan 2016
Complete solution to problem in OP:
%Change input 'data' and 'full' to separate HH and MM into separate columns
%So Year, DOY, Hour, Min, Var1
%Create Var1 as NaN in 'full'
%get time vectors for 'data' and 'full'
t = datenum(Year, 1, DOY, Hour, Minute, 1);
ft = datenum(Year, 1, DOY, Hour, Minute, 1);
datadates = round(datevec(t));
fulldates = round(datevec(ft));
[~, index] = ismember(datadates, fulldates, 'rows');
full(index,:) = data;
Thanks to Guillaume for solving the rest of this here: http://www.mathworks.com/matlabcentral/answers/184017#answer_171949

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!