Main Content

openfig

Open figure saved in FIG-file

Description

example

openfig(filename) opens the figure saved in the MATLAB® figure file (FIG-file) called filename.

Warning

Security Considerations: The openfig function might execute code contained in a FIG-file as it loads the graphics objects. Avoid calling openfig on untrusted FIG-files.

openfig(filename,copies) specifies whether to open a new copy of the figure in the case that a copy is already open. If you do not want to create a new copy, set copies to 'reuse'. The 'reuse' option brings the existing figure to the front of the screen. To open a new copy of the figure regardless of whether a copy is already open, set copies to 'new'. The 'new' option is the default behavior.

example

openfig(___,visibility) specifies whether to open the figure in a visible or invisible state. To display the figure, set visibility to 'visible'. If you do not want to display the figure, use the 'invisible' setting. You can use this option with any of the input argument combinations in the previous syntaxes.

fig = openfig(___) returns the figure object. Set properties of the figure object to modify its appearance or behavior. For a list of properties, see Figure Properties.

Examples

collapse all

Create a surface plot and save the figure as a MATLAB figure file. Then, close the figure.

surf(peaks)
savefig('MySavedPlot.fig')
close(gcf)

Open the saved figure.

openfig('MySavedPlot.fig')

Create a surface plot and make the figure invisible. Then, save the figure as a MATLAB figure file. Close the invisible figure.

surf(peaks)
set(gcf,'Visible','off')
savefig('MySavedPlot.fig')
close(gcf)

Open the saved figure and make it visible on the screen.

openfig('MySavedPlot.fig','visible')

Input Arguments

collapse all

File name of saved figure, specified as a character vector or string. You do not have to specify the full file path, as long as it is on your MATLAB path. Including .fig in the file name is optional.

Example: openfig('MySavedFigure.fig')

Control for opening multiple copies of the figure, specified as one of these values:

  • 'new' — Open a new copy of the figure, even if a copy already exists on the screen.

  • 'reuse' — Open a new copy of the figure only if one does not exist. If a copy exists, then bring the existing copy to the front of the screen. If the figure is off the screen, then 'reuse' repositions the figure so that it is completely on the screen. This option helps provide compatibility with different screen sizes and resolutions by ensuring that the figure displays on screen.

Example: openfig('MySavedFigure.fig','reuse')

Figure visibility, specified as one of these values:

  • 'visible' — Open the saved figure in a visible state. If the MATLAB figure file contains an invisible figure, then you can use this option to make the figure visible when it opens.

  • 'invisible' — Open the saved figure in an invisible state.

Example: openfig('MySavedFigure.fig','invisible')

Output Arguments

collapse all

Figure object. Set properties of the figure to change the appearance or behavior of the opened figure. For a list of properties, see Figure Properties.

Limitations

  • Do not use openfig to open FIG-files created with GUIDE. Use the guide function instead.

Version History

Introduced before R2006a