Plotting time vector in seconds on x-axis in HMS

2 visualizaciones (últimos 30 días)
Tom_S
Tom_S el 23 de Feb. de 2016
Comentada: Peter Perkins el 24 de Feb. de 2016
Hello,
I have a time vector that I use together with my data. I have RMS data every 4 seconds so the time vector only has values every 4 seconds. As I plot my data in function of the time vector, I want to get Hour:Minutes:seconds on the x-axis instead of only seconds. I tried functions but none of them seems to give good results, can anyone help me?
tRms=0,4,8,12,16,20,24,........... (1x300 double)
vRunRmsCf = (22x300 double)
semilogy(tRms,vRunRmsCf(selectPlotCf,:))
xlim([0 max(tRms)]);
ylim([0.0000001 0.0001]);
xlabel( 'Time [s] ' );
ylabel( 'RMS Velocity [m/s] ' );

Respuestas (1)

dpb
dpb el 23 de Feb. de 2016
Prior to R2015, use datenum and convert to datenumbers and plot against them and then datetick to display the axis with time markings.
Newer versions have the datetime class with builtin methods including plot being time-aware...
  1 comentario
Peter Perkins
Peter Perkins el 24 de Feb. de 2016
In R2014b or later, duration might be a better choice than datetime, since the times are really elapsed time since 0. Unfortunately, the semilogx function doesn't currently accept datetimes or durations, only plot does.
However, you might still be able to leverage duration just to get the tick labels you want:
tRms = seconds(0:4:299*4);
vRunRmsCf = rand(22,300);
semilogy(seconds(tRms),vRunRmsCf)
xlim(seconds([0 max(tRms)]));
ylim([0.0000001 0.0001]);
xlabel( 'Time [hh:mm:ss] ' );
ylabel( 'RMS Velocity [m/s] ' );
xticks = get(gca,'XTick');
xticklabels = cellstr(duration(0,0,xticks));
set(gca,'XTickLabel',xticklabels)

Iniciar sesión para comentar.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by