Quantcast

Documentation Center

  • Trial Software
  • Product Updates

gcf

Current figure handle

Syntax

Description

example

h = gcf returns the current figure handle. If a figure does not exist, then gcf creates a figure and returns its handle. You can use the figure handle to query and modify figure properties. For more information, see Figure Properties.

Examples

expand all

Specify Properties for Current Figure

Set the background color and remove the toolbar for the current figure using the gcf command.

figure
surf(peaks);
set(gcf,'Color',[0,0.5,0.5],...
        'Toolbar','none')

More About

expand all

Current Figure

The current figure is the target for graphics output. It is the figure window in which graphics commands such as plot, title, and surf draw their results. It is typically the last figure created or the last figure clicked with the mouse.

User interaction can change the current figure. If you need to access a specific figure, store the figure handle in your program code when you create the figure and use this handle instead of gcf.

Tips

  • To view a list of all figure properties, execute get(gcf).

  • To get the handle of the current figure without forcing the creation of a figure if one does not exist, query the CurrentFigure property on the root object.

    h = get(0,'CurrentFigure')

    MATLAB® returns h as an empty array if there is no current figure.

See Also

| | | | |

Was this topic helpful?