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!