cla

Syntax

Description

example

cla deletes all graphics objects that have visible handles from the current axes. The handle is visible if the HandleVisibility property of the object is set to 'on'.

The next plot added to the axes uses the first color and line style based on the ColorOrder and LineStyleOrder properties of the axes. The cla command resets the ColorOrderIndex and LineStyleOrderIndex properties of the current axes to 1.

example

cla reset deletes graphics objects from the current axes regardless of their handle visibility. It also resets axes properties to their default values, with the exception of the Position and Units properties.

example

cla(ax) deletes all graphics objects that have visible handles from the axes specified by ax instead of the current axes. The next plot added to the axes uses the first color and line style based on the ColorOrder and LineStyleOrder properties of the axes.

cla(ax,'reset') deletes graphics objects from the axes specified by ax, regardless of their handle visibility. It also resets axes properties to their default values, with the exception of the Position and Units properties.

Examples

expand all

Clear Current Axes

Plot two sine waves. Then, clear the line plots from the axes.

x = linspace(0,2*pi);
y1 = sin(x);
y2 = sin(2*x);

plot(x,y1)
hold on
plot(x,y2)

cla

cla clears the line plots and resets the ColorIndex and LineStyleIndex properties of the axes to 1. Subsequent plots start from the beginning of the color order and line style order. For example, plot another sine wave.

y3 = sin(3*x);
plot(x,y3)
hold off

Clear Objects from Specific Axes

Create a figure with two subplots and add plots to both axes.

ax1 = subplot(2,1,1);
surf(peaks)

ax2 = subplot(2,1,2);
contour(peaks)

Clear the surface plot from the upper subplot.

cla(ax1)

Now, reset all axes properties for the upper subplot, including the camera properties that control the view, by using the optional input argument 'reset'.

cla(ax1,'reset')

Clear Axes and Reset All Axes Properties

Create a line plot and set the axis limits.

x = linspace(0,2*pi);
y = sin(x);

plot(x,y)
axis([0,5,-2,2])

Clear the line plot from the axes and reset all the axes properties to their default values. cla reset resets all properties of the current axes, except for the Position and Units properties.

cla reset

Input Arguments

expand all

ax — Axes objectaxes object

Axes object. Use ax to clear a specific axes, instead of the current axes.

More About

expand all

Tips

  • cla only deletes objects with a HandleVisibility property set to 'on'. Therefore, if the HandleVisibility of an object is set to 'callback' and you are in a callback, then cla does not delete it.

  • If an axes does not exist, then cla creates one.

See Also

Functions

Properties

Was this topic helpful?