MATLAB Answers


Can I label dates on the x-axis that does not correspond to the exact timing of my data?

Asked by Michael
on 3 Aug 2012

I want to have ticks and labels (yyyy) on the horizontal axis that correspond to the turn of a year e.g. for 2000, the MATLAB serial code is 730486. I only want to have a tick for every second year. I have converted the data set into monthly frequency from December 1993 to July 2012 where I use last value available in very month, sometimes not necessarily the last calendar day (due to weekends, bank holidays, etc. - data availability) e.g. 29/07/2011. My (time-series) y variables are only available for these dates. I have been plotting these against the time they were measured so as to get an approximately accurate graph. Is there any way of having the x axis tick exactly at the turn of the year and once only every two years?

So far I tried:

hold on

but it does not produce any labels or ticks on the time/horizontal axis since my dates do not include the values 1994:2:2012.



No products are associated with this question.

1 Answer

Answer by per isakson
on 4 Aug 2012
Edited by per isakson
on 4 Aug 2012

Yes. See documentation on

     XTick       vector of data values locating tick marks
     XTickLabel  ... strings to use as labels for tick marks ... 

datetick might be smarter than I think, i.e. it takes care of XTickLabel. However your xtic must take values in the interval defined by your n; "data values" refers to your n.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!