MATLAB: Whats wrong with the following commands

axisgcaplotxlim

% The plotted x-axis goes from 0 to 1, instead of 20. Why?
ax = gca;
ax.xlim = [0 20];
drawnow

Best Answer

By default, calling PLOT resets most of the axes properties. See the description of "hold off" in the documentation for HOLD as well as the description of the axes property NextPlot for more information. To do what you want, use HOLD or the NextPlot axes property.