Plotting only the year of a column vector with full date
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Naweed Niaz
el 21 de Oct. de 2020
Comentada: Peter Perkins
el 19 de Nov. de 2020
I have a column vector with the dates in the format "MM/dd/yyyy." I would like to plot this against another vector, but only using the year part of the date. How can I extract the yyyy part and assign it to a new vector variable to be able to plot it?
2 comentarios
Rik
el 21 de Oct. de 2020
Do you have tyhe dates as a datetime vector, as a string vector, or as a cell vector of chars? And what did you try already?
Respuesta aceptada
Adam Danz
el 21 de Oct. de 2020
Editada: Adam Danz
el 23 de Oct. de 2020
Demo:
dt = datetime(1999,01,01) + days(1:100:5000);
y = rand(size(dt));
ax = gca();
plot(dt,y)
xtickformat(ax, 'yyyy')
% or
datetick(ax, 'x', 'yyyy', 'keeplimits')
1 comentario
Peter Perkins
el 19 de Nov. de 2020
Don't use datetick in a datetime plot. xtickformat is the way to go.
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!