Autocomplete the datetime series
2 views (last 30 days)
Show older comments
Hello, I have a time series as attached. The first, second, third and fourth column contains year, day, month, and hour, where the hour column runs from 0 - 23h. However, from 1st March, 23h onwards, no data are available. I want to create a datetime field from 1946, 2nd March onwards which ends at 31st December, with time frames 0-23 hrs. The value field can be filled with NaN in this case. Likewise, I have many sets of years and want to generalize the code in which the code can identify the enddate and endtime for which the data ends/missing and complete the datetime series till the end of the year, i.e.,
1946 12 31 23 NaN
Any help in this?
0 Comments
Accepted Answer
KL
on 28 Aug 2017
Edited: KL
on 28 Aug 2017
something like this? Try with a bigger dataset with occasional gaps.
ts_ref = (datetime('01/01/1946 00:00:00'):hours(1):datetime('01/02/1946 00:00:00'))'; %timestamp with no gaps
ts_act = ts_ref;
ts_act(15:18)=[]; %create some gaps (your datetime vector)
val = rand(size(ts_act));
newVal = nan(size(ts_ref));
dummy_data = table(ts_act,val)
[~, ind_ts_ref, ind_ts_act] = intersect(ts_ref,ts_act);
newVal(ind_ts_ref) = val;
dummy_data_new = table(ts_ref,newVal)
0 Comments
More Answers (0)
See Also
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!