how to change datatip from datenum format to datestr format
이전 댓글 표시
Hi everyone,
basically I'm trying to change datatip properties, in particular I'm trying to change the format of datatips for dates from datanum format to a string format (as 'dd/MM/yyyy').

In this case, the variables plotted are:
- 'dates': contains the dates as "datenum" format so its format is 'double';
- 'ptot_cumpl' and 'capInit' are 'double' format variables.
- I'm trying to understand how to do it for the "Total Portfolio" line that is the subplot1, then I'll do the same for all the others.
aa = plot(dates,ptot_cumpl+capInit,'k-','LineWidth',2);
xlim([dates(1) dates(end)+20]);
datetick ('x','mmm YYYY','keeplimits','keepticks');
grid on;
ytickformat('usd');
aa.DataTipTemplate.DataTipRows(1).Label = 'Date';
aa.DataTipTemplate.DataTipRows(2).Label = 'Cum Profit';
aa.DataTipTemplate.DataTipRows(2).Format = '%.0f';
Then I tried to change the values for "DataTipRows(1)" but I got this error:
aa1 = dataTipTextRow('Date',datestr(dates,'dd/MM/yyyy'));
aa.DataTipTemplate.DataTipRows(1) = aa1;
Error using matlab.graphics.datatip.DataTipTemplate/set.DataTipRows
Value must be a string scalar or a character vector with the name of a data property, such as 'XData', or it must be a vector or a function handle.
I tried also writing the last 2 lines as follows but it seems all the contained data is applied to each x axis step:
aa.DataTipTemplate.DataTipRows(1) = datestr(dates,'dd/MM/yyyy');
Warning: Error creating or updating Text
Error in value of property String
Text length might be too long to display.
Warning: Error creating or updating Text
Error in value of property String
Text length might be too long to display.
Warning: Error creating or updating Text
Error in value of property String
Text length might be too long to display.
Warning: Error creating or updating Text
Error in value of property String
Text length might be too long to display.

I tried then also converting the date variable to a string array but I get again an error.
aa.DataTipTemplate.DataTipRows(1) = string(datestr(dates));
Error using matlab.graphics.datatip.DataTipTemplate/set.DataTipRows
Label must be either a string scalar or character vector.
Thanks everyone! ;)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!