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!