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.
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.
clf([fig](#mw%5Fea64c374-ccb0-4b63-86ca-b356688d4e2c),'reset')
deletes all children of the specified figure and resets its properties.
f = clf(___)
returns the figure for any of the previous syntaxes.
Examples
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];
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)
f2 = figure; plot((1:10).^2)
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) ...
- 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2) ...
- 1/3*exp(-(x+1).^2 - y.^2)
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
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
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:
- Properties that do not have a default value, such as
Number
- Properties that have a value that depends on user interaction, such as
CurrentObject
andSelectionType
- Properties that control the figure size, such as
Position
andUnits
- Properties that control the figure window behavior and tools, such as
WindowStyle
,MenuBar
, andToolBar
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
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.