savefig - Save figure as FIG-file - MATLAB (original) (raw)
Syntax
Description
savefig([filename](#bt0w30o-1-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.
savefig([fig](#bt0w30o-1-H),[filename](#bt0w30o-1-filename))
saves the specified figure fig
.
savefig([fig](#bt0w30o-1-H),[filename](#bt0w30o-1-filename),[version](#bt0w30o-1-compact))
creates the file using the specified MAT-file version. Valid versions are"-v7.3"
, "-v7"
, and"-v6"
. (since R2024b)
Examples
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 arrayfig
. Save the figures to the fileTwoFiguresFile.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
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 asUntitled.fig
.
If the specified file name does not include a .fig
file extension, thensavefig
appends the extension.savefig
does not accept other file extensions.
Example: fig = figure; savefig(fig,"myfigure.fig")
saves the figure fig
asmyfigure.fig
.
Example: fig = [figure figure]; savefig(fig,"twofigures.fig")
saves the figures in the arrayfig
astwofigures.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 settings. To view or set the default MAT-file version, go to the Home tab and in theEnvironment section, click Settings. Select > > 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 theversion
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 theopenfig
oropen
function. For example: 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 thesave
function to create a MAT-file.
Version History
Introduced in R2013b
MATLAB issues a warning if you specify the "compact"
option. This option saves the same compact version of the FIG-file thatsavefig
saves by default. Thus, the"compact"
option is unnecessary. In a future release, the"compact"
option will be removed.
When you create a FIG-file, you can specify the MAT-file version as"-v7.3"
, "-v7"
, or"-v6"
.
savefig
stores files using the compact format by default. As a result, if you save FIG-files in R2024b, you can open them only in R2014b and later release. Previously, savefig
stored an extra copy of the figure that you could open in R2014a and earlier releases. This change reduces the file size by approximately 50%.
If you specify the "compact"
option, MATLAB saves the same compact version of the FIG-file that it saves by default. In a future release, the "compact"
option will be removed.
You cannot specify the "compact"
option and theversion
argument together.