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

 Accepted Answer

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

More Answers (1)

Fausto Tenini
Fausto Tenini on 7 Mar 2019

0 votes

thanks a lot Adam

2 Comments

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';
thanks

Sign in to comment.

Products

Release

R2018b

Community Treasure Hunt

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

Start Hunting!