datetime function vertical line
Show older comments
I have a plot where I use a datetime vector for x-axis (see example below). Now I want to make a vertical line within this plot, but when i use this:
x=17-Aug-2017 09:37:00
line([x x],[0 50])
I get this error:
Error using matlab.graphics.axis.decorator.DatetimeRuler/makeNumeric
Cannot combine or compare a datetime array with a time zone with one without a time zone.
Error in matlab.graphics.internal.makeNumeric
Example of first three samples in my datetime vector of my originally plotted data:
15-Aug-2017 17:58:58
15-Aug-2017 18:00:58
15-Aug-2017 18:02:58
Accepted Answer
More Answers (2)
Adam Danz
on 5 Feb 2019
You're probably not using datetime formated variables. This works:
dt = datetime({'15-Aug-2017 17:58:58'
'15-Aug-2017 18:00:58'
'15-Aug-2017 18:02:58'});
figure
plot(dt, [40 45 50], '-o')
x=datetime('17-Aug-2017 09:37:00') % <-- make sure it's actually 'datetime'
line([x,x],[0 50])
1 Comment
Sean de Wolski
on 5 Feb 2019
In newer releases:
xline(x)
Lieke Numan
on 6 Feb 2019
Edited: Lieke Numan
on 6 Feb 2019
0 votes
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!