HOLD Plot Hold Toggle Function

Section: Handle-Based Graphics


Toggles the hold state on the currently active plot. The general syntax for its use is

where state is either


to turn hold on, or


to turn hold off. If you specify no argument then hold toggles the state of the hold:


You can also specify a particular axis to the hold command


where handle is the handle for a particular axis.

Function Internals

The hold function allows one to construct a plot sequence incrementally, instead of issuing all of the plots simultaneously using the plot command.


Here is an example of using both the hold command and the multiple-argument plot command to construct a plot composed of three sets of data. The first is a plot of a modulated Gaussian.
--> x = linspace(-5,5,500);
--> t = exp(-x.^2);
--> y = t.*cos(2*pi*x*3);
--> plot(x,y);

We now turn the hold state to 'on', and add another plot sequence, this time composed of the top and bottom envelopes of the modulated Gaussian. We add the two envelopes simultaneously using a single plot command. The fact that hold is 'on' means that these two envelopes are added to (instead of replace) the current contents of the plot.

--> plot(x,y);
--> hold on
--> plot(x,t,'g-',x,-t,'b-')