www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/LabelxAxisTickswith2digitYearsExample.m
%% Label x-Axis Ticks with 2-digit Years % Graph population data for the 20th Century taken from the 1990 US census % and label _x_-axis ticks with 2-digit years. % Copyright 2015 The MathWorks, Inc. %% % Create time data by decade. t = (1900:10:1990)'; %% % Enter total population counts for the USA. p = [75.995 91.972 105.711 123.203 131.669 ... 150.697 179.323 203.212 226.505 249.633]'; %% % Convert years to serial date numbers using the |datenum| function, and % then create a bar graph of the data. figure bar(datenum(t,1,1),p) %% % Replace _x_-axis ticks with 2-digit years. The numeric identifier |11| % corresponds to the predefined MATLAB(R) date format |'yy'|. dateFormat = 11; datetick('x',dateFormat)