%% Add Month Labels to Plot and Preserve Number of Ticks  

% Copyright 2015 The MathWorks, Inc.


%% 
% Select a starting date. 
startDate = datenum('01-01-2009');  

%% 
% Select an ending date. 
endDate = datenum('12-31-2009');  

%% 
% Create a variable, |xdata|, that corresponds to the number of months between
% the start and end dates. 
xData = linspace(startDate,endDate,12);  

%% 
% Plot random data. 
figure
stairs(xData,rand(1,12))  

%% 
% Set the number of |XTicks| to the number of points in |xData|. 
ax = gca;
ax.XTick = xData;  

%% 
% Label the _x_-axis with month names, preserving the total number of ticks
% by using the |'keepticks'| option. 
datetick('x','mmm','keepticks')      

