%% Label x-Axis and Preserve Axis Limits
% 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')

% Copyright 2015 The MathWorks, Inc.