Adding date tick marks to a Matlab plot

666 Views Asked by At

I have a plot of time series data, and I would like to replace the tick marks of the x-axis (automatically I have the number of the ordered observations) with the date when the value is observed. I would like to have a tick mark every 5 years for example. I know how to do it with R, but with MATLAB seems so complicated and I'm not getting the result I want.

1

There are 1 best solutions below

1
On BEST ANSWER

There is an answer on the Mathworks website that I think you will find helpful: http://www.mathworks.com/matlabcentral/answers/92565-how-do-i-control-axis-tick-labels-limits-and-axes-tick-locations. Basically what you want to do is manipulate the XTick or XTickLabel attributes of the current axis handle. Lets say I have a plot that spans 100 years from 1900 - 2000. After creating the plot, I can set year labels in 5 year increments by doing:

set(gca, 'XTick', 1900:5:2000);