Main Content
savefig
Save figure and contents to FIG-file
Syntax
Description
example
savefig[
saves the current figure to a FIG-file named filename
]
. filename
.fig
example
savefig[
saves the figures identified by the graphics array H
,filename
]H
to a FIG-file named
.filename
.fig
savefig[
saves the specified figures in a FIG-file that can be opened only in MATLAB® R2014b or
later releases. The H
,filename
,'compact'
]'compact'
option reduces the size of the .fig
file and the time required to create the file.
Examples
collapse all
Save Current Figure to FIG-File
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.
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:
figs = openfig['TwoFiguresFile.fig'];
figs
contains the handles of the two figures created.
Save Figure Using 'compact'
Option
Save a figure using the compact option:
h = figure surf[peaks] savefig[h,'PeaksFile.fig','compact']
To open the figure, use the command:
openfig['PeaksFile.fig'];
Input Arguments
collapse all
H
— One or more figures
single figure | array of figures
One or more figures, specified as a single figure or an array of figures.
filename
— File name
'Untitled.fig'
[default] |
character vector | string
File name, specified as a character vector or string. If you do not specify a file name, then MATLAB saves the file as Untitled.fig
, which is the default.
If the specified file name does not include a .fig
file extension, then MATLAB appends the
extension. savefig
does not accept other file extensions.
Example: 'ExampleFile.fig'
Data Types: char
| string
'compact'
— File format for R2014b or later releases
'compact'
File format for R2014b or later releases of MATLAB, specified as 'compact'
. This option results in smaller
.fig
files. However, do not use the 'compact'
option if you want to open the .fig
file in versions of MATLAB before R2014b.
Tips
You must use MATLAB to open files saved using
savefig
. To open the file, pass the file name to the functionopenfig
oropen
. 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 thesave
function to create a MAT-file.
Version History
Introduced in R2013b