Using datenum for fraction of a second
22 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bruno Rodriguez
el 10 de Mzo. de 2017
Comentada: Walter Roberson
el 11 de Mzo. de 2017
I am looking for a ways to convert some dates into datenum, given their special format. My dates look as follows:
'2017-02-28 21:36:51'
'2017-02-28 21:36:51.5'
'2017-02-28 21:36:52'
'2017-02-28 21:36:52.5'
'2017-02-28 21:36:53'
'2017-02-28 21:36:53.5'
etc. etc. etc.
In other words, the format of the dates alternates, such that every other entry has an additional 500 milliseconds at the end of it. How can I convert these to datenum simultaneously, given their different formats? (or at least, how can I convert dates with .5 to datenum?). I cannot skip or ignore any of this data.
Thanks
1 comentario
Walter Roberson
el 10 de Mzo. de 2017
Would datetime format instead of datenum format be acceptable?
datenum() tends to be more flexible in format conversion but sometimes datetime() is easier.
Respuesta aceptada
Walter Roberson
el 10 de Mzo. de 2017
dates = {'2017-02-28 21:36:51'
'2017-02-28 21:36:51.5'
'2017-02-28 21:36:52'
'2017-02-28 21:36:52.5'
'2017-02-28 21:36:53'
'2017-02-28 21:36:53.5'};
temp = regexprep(dates, ':\d\d$', '$&.0', 'lineanchors');
Now temp is in consistent format
2 comentarios
Walter Roberson
el 11 de Mzo. de 2017
datestr(datenum(temp), 'YYYY-mm-DD hh:MM:ss.fff')
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!