Main Content

savefig

Save figure as FIG-file

Description

savefig(filename) saves the current figure as a FIG-file with the specified filename. The FIG-file is stored in a compact format, and the resulting figure is compatible with MATLAB® R2014b and later.

example

savefig(fig,filename) saves the specified figure fig.

example

savefig(fig,filename,version) creates the file using the specified MAT-file version. Valid versions are "-v7.3", "-v7", and "-v6". (since R2024b)

example

Examples

collapse all

Create a surface plot of the peaks function. Save the figure to the file PeaksFile.fig.

figure
surf(peaks)
savefig("PeaksFile.fig")

To open the saved figure, use the command:

openfig("PeaksFile.fig");

MATLAB creates a new figure using the saved .fig file.

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

fig(1) = figure;
z = peaks;
surf(z)
fig(2) = figure;
plot(z)

savefig(fig,"TwoFiguresFile.fig")
close(fig)

To open the two figures, use the command:

myfigs = openfig("TwoFiguresFile.fig");

myfigs contains the two Figure objects created.

Save a figure using the "-v7.3" MAT-file version.

fig = figure;
surf(peaks)
savefig(fig,"PeaksFile.fig","-v7.3")

To open the saved figure, use the command:

openfig("PeaksFile.fig");

Input Arguments

collapse all

Target figure, specified as a Figure object or an array of Figure objects.

Example: savefig("myfigure.fig") saves the current figure as myfigure.fig.

File name, specified as string scalar or character vector. If you do not specify a file name, savefig saves the file as Untitled.fig.

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

Example: fig = figure; savefig(fig,"myfigure.fig") saves the figure fig as myfigure.fig.

Example: fig = [figure figure]; savefig(fig,"twofigures.fig") saves the figures in the array fig as twofigures.fig.

Data Types: char | string

Since R2024b

MAT-file version, specified as one of these values:

  • "-v7.3" — Version that includes all of the "-v7" features and supports FIG-files larger than 2 GB.

  • "-v7" — Version that uses compression and supports FIG-files up to 2 GB. This version also supports Unicode® character encoding, which enables file sharing between systems that use different default character encoding schemes.

  • "-v6" — Legacy version that does not use compression or Unicode character encoding.

If you do not specify the version, savefig uses the default MAT-file version specified in Preferences. To view or set the default MAT-file version, go to the Home tab and in the Environment section, click Preferences. Select MATLAB > General > MAT and Fig Files and then choose a MAT and Fig files save format option.

Note

The saved FIG-file is compatible with R2014b and later regardless of the value of the version argument. The FIG-file cannot be opened in R2014a and earlier releases. (since R2024b)

Tips

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

    openfig("MyFile.fig")

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

Version History

Introduced in R2013b

expand all