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

 Akzeptierte Antwort

Adam Danz
Adam Danz am 7 Mär. 2019

0 Stimmen

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

Weitere Antworten (1)

Fausto Tenini
Fausto Tenini am 7 Mär. 2019

0 Stimmen

thanks a lot Adam

2 Kommentare

Peter Perkins
Peter Perkins am 11 Mär. 2019
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';
Fausto Tenini
Fausto Tenini am 12 Mär. 2019
thanks

Melden Sie sich an, um zu kommentieren.

Produkte

Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by