clf - Clear figure - MATLAB (original) (raw)

Syntax

Description

clf([fig](#mw%5Fea64c374-ccb0-4b63-86ca-b356688d4e2c)) deletes all children of the specified figure that have visible handles.

example

clf('reset') deletes all children of the current figure regardless of their handle visibility. It also resets the figure properties to their default values, except for some figure properties unaffected by reset. Alternatively, you can reset the figure using theclf reset command without parentheses.

example

clf([fig](#mw%5Fea64c374-ccb0-4b63-86ca-b356688d4e2c),'reset') deletes all children of the specified figure and resets its properties.

example

f = clf(___) returns the figure for any of the previous syntaxes.

example

Examples

collapse all

Create a line plot. Then, set the background color of the current figure.

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

f = gcf; f.Color = [0 0.5 0.5];

Figure contains an axes object. The axes object contains an object of type line.

Clear the figure using a call to clf. The function call deletes the plot. However, it does not affect the background color of the figure.

Now, reset the figure properties and return the children of the figure. clf('reset') resets the background color to its default value.

f = clf('reset'); f.Children

ans = 0×0 empty GraphicsPlaceholder array.

Create two figures, each with a line plot. Set the background color of the first figure.

f1 = figure('Color','b'); plot(1:10)

Figure contains an axes object. The axes object contains an object of type line.

f2 = figure; plot((1:10).^2)

Figure contains an axes object. The axes object contains an object of type line.

Clear the line plot from the first figure without resetting the background color of the figure.

Now, reset all properties of the first figure.

Create a figure with a white background. Then, create a surface plot.

figure('Color','w') peaks

z = 3*(1-x).^2.*exp(-(x.^2) - (y+1).^2) ...

Figure contains an axes object. The axes object with title Peaks, xlabel x, ylabel y contains an object of type surface.

Clear the surface plot from the figure and reset all figure properties to their default values. clf reset resets all properties of the current figure, except for the Position, Units, PaperPosition, and PaperUnits properties.

Input Arguments

collapse all

Target figure, specified as a Figure object, a figure number, or an array of Figure objects or numbers.

If fig contains a figure number, MATLAB® searches for an existing figure that has its Number property set to that number. By default, theNumber property is displayed in the title of the figure.

Example: clf(f) clears Figure objectf.

Example: clf(1) clears figure number 1.

Example: clf([1 f]) clears figure number 1 andFigure object f.

More About

collapse all

A handle is visible to clf if theHandleVisibility property of the object is set to'on'. When you call clf in the Command Window or within a callback routine, the function deletes only those objects whoseHandleVisibility property is set to 'on'. It does not delete objects whose HandleVisibility property is set to'callback' or 'off'.

When clf resets the properties of a figure, some properties are not reset. These properties include:

Tips

Version History

Introduced before R2006a

expand all

When you call clf('reset') to reset figure properties, theMenuBar and ToolBar properties are unaffected.

Clear multiple figures at once by specifying the fig argument as an array of Figure objects or figure numbers.