MATLAB: Axis changes even after “axis equal”

axisMATLAB

I would like to plot a line on an axis without changing the XLim and YLim values. I obviously went through the "axis equal" command (or the ax.XLimMode='manual'; ax.YLimMode='manual';) but this doesn't seems to work.
Where am I doing wrong?
plot(1:10)
% XLim is not [1 10]

axis manual
plot(1:20)
% XLim should be again [1 10], instead it's [0 20] now

it works with
plot(1:10)
% XLim is not [1 10]
hold on
axis manual
plot(1:20)
% XLim should be again [1 10], instead it's [0 20] now
but I don't want to hold previous plots (it's an animation).
A workaround could be to use
ph=plot(1:10)
axis manual
hold on
delete(ph)
plot(1:20)
but I this seems over-complicated to do the simple thing I'm asking to…
I'm working with matlab R2015a

Best Answer

If you don't hold the plots, axis limits will be reset every time you call plot. For an animation, you can use hold and either delete plotted objects or change their data. That is,
hold on
h = plot(1:10);
<grab animation frame here>
delete(h)
h = plot(1:20);
and so on. Or you can change the data in h with
set(h,'xdata',1:20,'ydata',1:20)
Related Question