%% Label x-Axis and Preserve Axis Limits  

% Copyright 2015 The MathWorks, Inc.


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

%% 
% Select an ending date. 
endDate = datenum('11-15-2012');  

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

%% 
% Plot random data. 
figure
stem(xData,rand(1,50))  

%% 
% Label the _x_-axis with 4-digit years, preserving the _x_-axis limits
% by using the |'keeplimits'| option. 
datetick('x','yyyy','keeplimits')      

