Main Content

clf

Description

clf deletes all children of the current figure that have visible handles.

example

clf(fig) 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 the clf reset command without parentheses.

example

clf(fig,'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.

clf

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 = 
  0x0 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.

clf(f1)

Now, reset all properties of the first figure.

clf(f1,'reset')

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) ... 
   - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ... 
   - 1/3*exp(-(x+1).^2 - y.^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.

clf reset

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, the Number property is displayed in the title of the figure.

Example: clf(f) clears Figure object f.

Example: clf(1) clears figure number 1.

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

More About

collapse all

Visible Handles

A handle is visible to clf if the HandleVisibility 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 whose HandleVisibility property is set to 'on'. It does not delete objects whose HandleVisibility property is set to 'callback' or 'off'.

Figure Properties Unaffected by Reset

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

  • Properties that do not have a default value, such as Number

  • Properties that have a value that depends on user interaction, such as CurrentObject and SelectionType

  • Properties that control the figure size, such as Position and Units

  • Properties that control the figure window behavior and tools, such as WindowStyle, MenuBar, and ToolBar

Tips

  • To clear the contents of a figure, you can alternatively use Clear Figure from the figure window's Edit menu. Using Clear Figure deletes all children of the figure that have visible handles.

Version History

Introduced before R2006a

expand all

See Also

Functions

Properties