How to add date and time in a plot by command in matlab 2012?

2 ビュー (過去 30 日間)
Deborah Johnson
Deborah Johnson 2022 年 5 月 19 日
コメント済み: Star Strider 2022 年 5 月 19 日
At my workplace, we have MatLab R2012a. I have been asked to plot a graph and add the 'date and time' on the top or bottom of the graph - timestamp. How it can be done by using either the editor command or the graph.s title?
I have tried text(0.5,0.5, datestr(clock), 'HorizontalAlignment', 'left', 'VerticalAlignment','top') and the command is accepted but nothing shows up on the graph?
Please help. Thanks.
  1 件のコメント
Cris LaPierre
Cris LaPierre 2022 年 5 月 19 日
There is nothing wrong with the code you have shared. Is there anything unique about your install? OS?

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

採用された回答

Star Strider
Star Strider 2022 年 5 月 19 日
I no longer have access to R2012a, so I cannot test this with it.
The code you posted works correctly in R2022a, however R2012a may require a separate sprintf call —
title(sprintf('%s', datestr(clock)))
See if that works.
All of these work correctly in R2022a:
text(0.5,0.5, datestr(clock), 'HorizontalAlignment', 'left', 'VerticalAlignment','top')
title(datestr(clock))
ylabel(sprintf('%s', datestr(clock)))
.
  2 件のコメント
Deborah Johnson
Deborah Johnson 2022 年 5 月 19 日
編集済み: Deborah Johnson 2022 年 5 月 19 日
Hello Star and Chris,
The OS is Windows 10, so don't know why it doesn't show up? However, the other code you share works. Thank you! I also needed to add a Test Name to it.
The code now has the 'Test Name and Timestamp' coming up automatically now!! I've been wrestling with this for over a month. I do have MatLab 2022 at home through DAU Coursera but it takes time to purchase a new license. So, I've been bouncing between 2012 to 2022...LOL
title(sprintf('TITLE: %s DATE: %s', 'XYZ', datestr(clock)))
Thank you so much Star! You have made my day. :-)
Star Strider
Star Strider 2022 年 5 月 19 日
As always, my pleasure!
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2012a

Community Treasure Hunt

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

Start Hunting!

Translated by