I have this code (where asset simulation is a variable):
plot(asset_simulation,'-','color','green')
dateFormat = 12;
datetick('x',dateFormat)
In which way can I insert a starting date for x axis, for example today's date (going into the future, linked to the size of asset simulation variable) instead of Jan00?
thanks a lot
Fausto

 采纳的回答

You need to specify the x coordinates. In this example, I create x coordinates that start 'today', have an interval of roughly 2 weeks, and extend until there is a date for each 'asset_simulation'.
asset_simulation = 1:20;
xdates = floor(now) + (0:length(asset_simulation)-1)*14; % date values, roughly 2 week interval
plot(xdates, asset_simulation, '-o') % specify the x date values
datetick('x', 12)
190307 094342-Figure 1.jpg

更多回答(1 个)

Fausto Tenini
Fausto Tenini 2019-3-7

0 个投票

thanks a lot Adam

2 个评论

In versions of MATLAB since about R2016b, you are probably better off plotting using datetimes:
asset_simulation = 1:20;
xdates = datetime('today') + calweeks(0:length(asset_simulation)-1);
plot(xdates, asset_simulation, '-o');
xax = get(gca,'XAxis');
xax.TickLabelFormat = 'MMMdd';

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Calendar 的更多信息

产品

版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by