Convert seconds to HH:MM:SS.FF
36 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yu
el 27 de Ag. de 2021
Comentada: Yu
el 27 de Ag. de 2021
I have time stamps that have hh:mm:ss and nanoseconds in different columns and want to convert them to hh:mm:ss.ff.
I did as following but have no idea what to do next.
Any ideas on how can I do this?
Thanks.
clear
load sample.mat
sample.SECONDS = datenum(sample.TIME)+sample.NANOSECONDS*10^(-9);
0 comentarios
Respuesta aceptada
Walter Roberson
el 27 de Ag. de 2021
sample.SECONDS = datenum(sample.TIME) + seconds(sample.NANOSECONDS*10^(-9));
sample.SECONDS.Format = 'hh:mm:ss.ff';
The second step will be rejected because datetime() objects have no 'ff' format specification. (And be careful, since for datetime() object, 'hh' is hour in 12 hour notation)
Perhaps you want to use datenum objects. However, datenum objects do not have a 'ff' specification either: they have a 'FF' specification.
I recommend
sample.SECONDS.Format = 'HH:mm:ss.SS';
3 comentarios
Walter Roberson
el 27 de Ag. de 2021
sample.SECONDS = sample.TIME + seconds(sample.NANOSECONDS*10^(-9));
sample.SECONDS.Format = 'HH:mm:ss.SS';
Más respuestas (0)
Ver también
Categorías
Más información sobre Startup and Shutdown 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!