![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1004515/image.png)
How to add date and time in a plot by command in matlab 2012?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Deborah Johnson
am 19 Mai 2022
Kommentiert: Star Strider
am 19 Mai 2022
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 Kommentar
Cris LaPierre
am 19 Mai 2022
There is nothing wrong with the code you have shared. Is there anything unique about your install? OS?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1004515/image.png)
Akzeptierte Antwort
Star Strider
am 19 Mai 2022
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!