MATLAB Answers


Inserting date and time variables into graphs title

Asked by Andrei Makarskiy on 18 Oct 2015
Latest activity Commented on by Andrei Makarskiy on 19 Oct 2015
Accepted Answer by Jan
I have the following code:
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.


I do not find the command days in the documentation. What kind of variable does it reply? Please post the type and the value.
>> start_end_time_days = days(start_end_time)
start_end_time_days =
BTW, where's the yesterdays comment, Jan? It helped )

Sign in to comment.

1 Answer

Answer by Jan
on 18 Oct 2015
Edited by Jan
on 18 Oct 2015
 Accepted Answer

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 Comment

That's solved the issue. Thanks ) I used the second one.

Sign in to comment.