How to plot a vertical line at a certain datetime

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'. ".

 採用された回答

Star Strider
Star Strider 2016 年 12 月 19 日

3 投票

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

2 件のコメント

K E
K E 2016 年 12 月 19 日
For me too.
Star Strider
Star Strider 2016 年 12 月 19 日
!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

タグ

質問済み:

K E
2016 年 12 月 19 日

コメント済み:

2016 年 12 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by