Main Content

gcf

Current figure handle

Syntax

Description

fig = 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.

example

Examples

collapse all

Set the background color and remove the toolbar for the current figure. Use the gcf command to get the current figure handle.

surf(peaks)
fig = gcf; % current figure handle
fig.Color = [0 0.5 0.5];
fig.ToolBar = 'none';

Figure containing a surface plot. The background color of the figure is blue-green and the toolbar has been removed.

More About

collapse all

Tips

  • 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.

    fig = get(groot,'CurrentFigure');
    
    MATLAB® returns fig as an empty array if there is no current figure.

Version History

Introduced before R2006a

See Also

Functions

Objects