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

    %% Maintain Current _x_-Axis Limits
% Use manual mode to maintain the current x-axis limits when you add more
% plots to the axes.
%
% First, plot a line.

% Copyright 2015 The MathWorks, Inc.

x = linspace(0,10);
y = sin(x);
plot(x,y);

%%
% Set the _x_-axis limits mode to manual so that the limits do not change.
% Use |hold on| to add a second plot to the axes.
xlim manual
hold on
plot(2*x,2*y)
hold off

%%
% The _x_-axis limits do not update to incorporate the new plot. 
%
% Switch back to automatically updated limits by resetting the mode
% to automatic.

xlim auto