Time series data formatting issues
显示 更早的评论
I have 15 minute interval time series data that is in the format:
MM/dd/yyyy hh:mm:ss a
However at 12:00:00 on each day the time stamp is recorded as
MM/dd/yyyy
with no hh:mm:ss a.
Therefore when I convert it from cell data to datetime, the values for the new day is recorded as a NaN.
How can I get each of the midnight "NaN"'s to record as MM/dd/yyyy hh:mm:ss a?
Thanks
回答(1 个)
Peter Perkins
2016-12-2
Clay, the simplest thing to do is just fill in the NaTs after the fact:
>> c
c =
'12/01/2016 10:00:00 PM'
'12/01/2016 11:00:00 PM'
'12/02/2016'
'12/02/2016 01:00:00 AM'
'12/02/2016 02:00:00 AM'
>> d = datetime(c,'Format','MM/dd/yyy hh:mm:ss a')
d =
12/01/2016 10:00:00 PM
12/01/2016 11:00:00 PM
NaT
12/02/2016 01:00:00 AM
12/02/2016 02:00:00 AM
>> d(isnat(d)) = datetime(c(isnat(d)),'Format','MM/dd/yyy')
d =
12/01/2016 10:00:00 PM
12/01/2016 11:00:00 PM
12/02/2016 12:00:00 AM
12/02/2016 01:00:00 AM
12/02/2016 02:00:00 AM
You could also find the "short" strings and append '00:00:00 AM' to them before calling datetime.
Hope this helps.
类别
在 帮助中心 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!