Plot where x axis is the date, Part 2 (edited)

1 visualización (últimos 30 días)
alpedhuez
alpedhuez el 5 de Jun. de 2018
Editada: Nithin Banka el 7 de Jun. de 2018
I would like to have x axis of the plot between April 20 2016 and May 18 2018. Please advise how to modify an example
xlim(datetime(2014,[7 8],[12 23]))
xtickformat('dd-MMM-yyyy')
(https://www.mathworks.com/help/matlab/matlab_prog/plot-dates-and-durations.html)
to the above setting.

Respuesta aceptada

Varun Garg
Varun Garg el 5 de Jun. de 2018
Suppose you want to plot a graph for dates between July 1,2012 to July 1,2016. One possible implementation is as follows:
xMin= datetime(2012,7,1)
xMax= datetime(2016,7,1)
xlim([xMin,xMax])
You can change the code accordingly now. Hope this works for you.

Más respuestas (2)

Nithin Banka
Nithin Banka el 5 de Jun. de 2018
Editada: Nithin Banka el 7 de Jun. de 2018
Assuming that you have the same number of data points as the number of dates. Create a datetime vector for the duration and plot your data against the datetime vector.
datetimeVector = datetime(2016, 4, 20):datetime(2018, 5, 18);
plot(datetimeVector, yourData); %yourData is what you want to plot against the duration
xlim([datetimeVector(1) datetimeVector(end)]);
xtickformat('dd-MM-yyyy');

monika shivhare
monika shivhare el 5 de Jun. de 2018
xlim(datetime([2016 2018],[4 5],[20 18]))
xtickformat('dd-MMM-yyyy')
  2 comentarios
alpedhuez
alpedhuez el 5 de Jun. de 2018
This did not work.
Nithin Banka
Nithin Banka el 7 de Jun. de 2018
For this to work, you need the x-axis values to be in 'datetime' datatype or else, this gives an error.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by