www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/LinePlotWithDatesExample.m

    %% Line Plot with Dates
% Create a line plot with datetime values on the _x_-axis. Then, change the
% format of the tick labels and the _x_-axis limits.
%%
% Create |t| as a sequence of dates and create |y| as random data. Plot the
% vectors using the |plot| function.
t = datetime(2014,6,28) + calweeks(0:9);
y = rand(1,10);
plot(t,y);
%%
% By default, |plot| chooses tick mark locations based on the range of
% data. When you zoom in and out of a plot, the tick labels automatically
% adjust to the new axis limits.
%%
% Change the _x_-axis limits. Also, change the format for the tick labels
% along the _x_-axis. For a list of formatting options, see the
% <docid:matlab_ref.bu6ia4o> function.
xlim(datetime(2014,[7 8],[12 23]))
xtickformat('dd-MMM-yyyy')