How to plot datetime array?
Show older comments
I would like to plot a vector, r, as a function of time. The two vectors I have are:
r'
1.0e+03 *
0.0179
0.0180
0.0184
0.0184
0.0189
0.0189
0.0189
0.0189
0.0190
0.0190
ds =
10×1 datetime array
02-Feb-2018 11:08:11
02-Feb-2018 12:08:13
02-Feb-2018 01:08:14
02-Feb-2018 02:08:15
02-Feb-2018 03:08:17
02-Feb-2018 04:08:18
02-Feb-2018 05:08:20
02-Feb-2018 06:08:21
02-Feb-2018 07:08:23
02-Feb-2018 08:08:24
However, when I try to plot them:
plot(datenum(ds), r, '-o')
datetick('x', 'dd-mmm-yyyy HH:MM:SS')
I get this graph (see attached). I would like for each point to have a corresponding time and date on the x-axis, if it is possible.
Accepted Answer
More Answers (1)
Aron Magesh
on 22 May 2020
2 votes
If you have used hold on function, make sure to use the hold off as well to avoid this error.
1 Comment
Bucks Lin
on 14 Apr 2022
wow!
thanks Aron!! your tips save my day.
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!