Plotting time vector in seconds on x-axis in HMS
조회 수: 3 (최근 30일)
이전 댓글 표시
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] ' );
댓글 수: 0
답변 (1개)
dpb
2016년 2월 23일
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
Peter Perkins
2016년 2월 24일
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)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!