MATLAB Answers

K E
0

How to plot a vertical line at a certain datetime

Asked by K E
on 19 Dec 2016
Latest activity Commented on by Star Strider
on 19 Dec 2016
I am using datetime to plot some time series data. I would like to add a vertical line to mark a certain date on the plot. How do I do this? Here is what I have tried.
% Make example time series data
t = datetime(2014,6,28) + calweeks(0:9);
y = rand(1,10);
plot(t,y); % Plot time series data
hold on;
tMark = datetime(2014,8,1); % Time to mark by a vertical line
plot([1 1]*tMark, get(gca, 'ylim'));
This returns the error "Undefined operator '*' for input arguments of type 'datetime'. ".

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Star Strider
on 19 Dec 2016
 Accepted Answer

This works:
plot([tMark tMark], ylim);