Retain current graph when adding new graphs
The hold function controls whether MATLAB® clears the current graph when you make subsequent calls to plotting functions (the default), or adds a new graph to the current graph.
hold all holds the graph and the current line color and line style so that subsequent plotting commands do not reset the ColorOrder and LineStyleOrder property values to the beginning of the list. Plotting commands continue cycling through the predefined colors and line styles from where the last graph stopped in the list.
hold reverses the current hold state. If the hold state is currently on, then a hold command sets the state to off. Similarly, if the hold state is currently off, then a hold command sets the state to on.
hold(axes_handle,...) applies the hold to the axes identified by the handle axes_handle. If several axes objects exist in a figure window, each axes has its own hold state. hold also creates an axes if one does not exist.
Test the hold state using the ishold function.
Create a graph, set hold to on, then create another graph in the same axes:
x = -pi:pi/20:pi; plot(sin(x)) hold on plot(cos(x)) hold off
If the range of subsequently added data is much greater than the original data, the original graph can become difficult to see in one axes. In these cases, it is usually better to use two separate axes. See subplot to create multiple axes in one figure.
hold toggles the NextPlot axes property between the add and replace.
hold on sets the NextPlot property of the current figure and axes to add. hold off sets the NextPlot property of the current axes to replace.