Documentation Center

  • Trial Software
  • Product Updates
我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

savefig

Save figure to FIG-file

Syntax

Description

example

savefig(filename) saves the current figure to a FIG-file named filename.

example

savefig(h,filename) saves one or more figures referred to by h, where h can be a single figure handle or an array of figure handles.

Examples

expand all

Save Current Figure to FIG-File

Create a surface plot of the peaks function. Save the figure to the file PeaksFile.fig. Close the figure after saving it.

figure;
surf(peaks);
savefig('PeaksFile.fig');
close(gcf)

To open the figure, use the command openfig('PeaksFile.fig').

Save Multiple Figures to FIG-File

Create two plots and store the figure handles in array h. Save the figures to the file TwoFiguresFile.fig. Close the figures after saving them.

h(1) = figure;
z = peaks;
surf(z)

h(2) = figure;
plot(z)

savefig(h,'TwoFiguresFile.fig');
close(h)

To open the two figures, use the command openfig('TwoFiguresFile.fig').

Input Arguments

expand all

h — Handle to one or more figuressingle figure handle | array of figure handles

Handle to one or more figures, specified as a single figure handle or an array of figure handles.

filename — file name'Untitled.fig' (default) | string

File name, specified as a string. If you do not specify a file name, then MATLAB® saves the file as Untitled.fig, which is the default.

If the specified string does not include a .fig file extension, then MATLAB appends the extension. savefig does not accept other file extensions.

Example: 'ExampleFile.fig'

More About

expand all

Tips

  • You must use MATLAB to open files saved using savefig. To open the file, pass the file name to the function openfig, hgload, or open. For example,

    openfig('ExampleFile.fig')

    opens the file, ExampleFile.fig, in MATLAB.

  • savefig saves the full MATLAB figure. To save only part of a figure, such as an axes, or to save handles in addition to the data, use the save function to create a MAT-file.

See Also

| | |

Was this topic helpful?