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

Learn moreOpportunities for recent engineering grads.

Apply TodayTo resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

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 v=datestr(exceldata(:,1)+693960,'dd/mm/yyyy') n=datenum(v,'dd/mm/yyyy') plot(n,exceldata(:,2)) xtic=[1994:2:2012]; set(gca,'XTick',xtic); datetick('x','yyyy','keeplimits','keepticks');

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.*

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.

## 0 Comments