フィルターのクリア

Inserting date and time variables into graphs title

4 ビュー (過去 30 日間)
Andrei Makarskiy
Andrei Makarskiy 2015 年 10 月 18 日
コメント済み: Andrei Makarskiy 2015 年 10 月 19 日
I have the following code:
startDate=datetime('03-Oct-2014','InputFormat','dd-MMM-yyyy');
endDate=datetime('15-Oct-2014','InputFormat','dd-MMM-yyyy');
start_end_time = endDate-startDate;
start_end_time_days = days(start_end_time);
When I try to set title on the plot like this:
Ticker = 'SPY';
title([Ticker, ' Bought in ', char(start_end_time_days), ' days before some event']);
I get an empty string: SPY Bought in days before some event
I experimented with the code removing char() and doing like:
title([Ticker, ' Bought in ', start_end_time_days, ' days before some event']);
though it didn't help either.
  2 件のコメント
Jan
Jan 2015 年 10 月 18 日
I do not find the command days in the documentation. What kind of variable does it reply? Please post the type and the value.
Andrei Makarskiy
Andrei Makarskiy 2015 年 10 月 19 日
編集済み: Andrei Makarskiy 2015 年 10 月 19 日
>> start_end_time_days = days(start_end_time)
start_end_time_days =
12
BTW, where's the yesterdays comment, Jan? It helped )

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

採用された回答

Jan
Jan 2015 年 10 月 18 日
編集済み: Jan 2015 年 10 月 18 日
Pure guessing:
If days replies the number of days as a double value:
Ticker = 'SPY';
title([Ticker, ' Bought in ', sprintf('%f', start_end_time_days), ...
' days before some event']);
Or shorter (and perhaps with %d instead of %f):
title(sprintf('%s Bought in %d days before some event', ...
Ticker, start_end_time_days));
  1 件のコメント
Andrei Makarskiy
Andrei Makarskiy 2015 年 10 月 19 日
That's solved the issue. Thanks ) I used the second one.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTitle についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by