Plot DateTime vector as elapsed time in seconds from start of meaurement
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Francis Dick
el 5 de Mzo. de 2018
Respondida: Benjamin Kraus
el 5 de Mzo. de 2018
Hi, I have a datetime vector in HH:mm:ss.SSS format corresponding to measurements from a wave gauge. I want to plot the data in a figure with the time being in seconds from the start of the recording, so the x-axis labels appear as 0,1,2,3,4,5.... in seconds, as opposed to 00:00:00, 00:00:30, 00:01:00...
I have used the datenum to create serial dates and datetick when plotting the figure but this results in the HH:mm:ss format which I don't want.
Thanks!
0 comentarios
Respuesta aceptada
Benjamin Kraus
el 5 de Mzo. de 2018
It sounds like you want to plot duration values. Let's say that t is your vector of datetime values. You can convert those to duration values by subtracting:
t = datetime('now')+minutes(0:0.5:10);
d = t-t(1); % Convert to duration since start of experiment.
d.Format = 's'; % Specify that you want to see seconds in the display.
Once you've converted, you can either plot the values directly:
plot(d, 1:21)
Or you can explicitly convert to seconds before plotting:
plot(seconds(d), 1:21)
xlabel('seconds')
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!