How can I display the date on a plot?

Hi! I'm working on a plot to show the displacements of a point at different times and I got the following:
I got the results I wanted on the plot but instead of showing the time in julian time, I want to show the date. I tried converting the time vector using the datestr command but it says that there is a subscript mismatch. Can someone help me with this? Thank you.

 採用された回答

Walter Roberson
Walter Roberson 2017 年 9 月 13 日

1 投票

If you have roughly R2015b or later (I would need to recheck the exact release) then where you have roughly
plot(Time, Displacement)
change that to
TimeDT = datetime(Time, 'ConvertFrom', 'juliandate', 'Format', 'yyyy-MM-dd'); %or as appropriate for format you want displayed
plot(TimeDT, Displacement)
The ability to use datetime objects as the "x" values did not start with R2014b with the rest of the Handle Graphics 2 (HG2) graphics system, so if you are in the R2014b to R2015b range possibly it was not yet available.

4 件のコメント

Agustin
Agustin 2017 年 9 月 13 日
Thank you so much for your quick reply! I will try this.
Agustin
Agustin 2017 年 9 月 13 日
編集済み: Agustin 2017 年 9 月 13 日
I've tried it but the datetime command is computing the date correctly. For example the first time value is 07-Jul-2016 23:56:17 and with datetime, I'm getting 2697-06-02, which is way incorrect. Why is this happening?
Walter Roberson
Walter Roberson 2017 年 9 月 14 日
You wrote, "instead of showing the time in julian time", so I took your word that what you have is indeed julian dates. However your values are instead consistent with datenum instead of julian dates. So in the code I posted replace 'juliandate' with 'datenum'
Agustin
Agustin 2017 年 9 月 14 日
It worked! Thank you so much!!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

質問済み:

2017 年 9 月 13 日

コメント済み:

2017 年 9 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by