Time series data formatting issues
Afficher commentaires plus anciens
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
Réponses (1)
Peter Perkins
le 2 Déc 2016
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.
Catégories
En savoir plus sur Dates and Time dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!