savefig
Save figure to a Nelson FIG file.
📝Syntax
savefig()
savefig(filename)
savefig(fig, filename)
savefig(fig, filename, version)
📥Input Arguments
Parameter Description
fig Figure graphics object or array of figure graphics objects. Every element must be a valid figure.
filename Character vector or string scalar. If filename has no extension, savefig appends .fig. Other extensions are rejected.
version Compatibility flag accepted for syntax compatibility: '-v7.3', '-v7', or '-v6'. Nelson stores the same Nelson FIG format for each value.
📄Description

savefig() saves the current figure returned by gcf() to Untitled.fig.

savefig(filename) saves the current figure to filename.

savefig(fig, filename) saves the specified figure or array of figures to one file.

savefig(fig, filename, version) accepts a version flag for syntax compatibility. The flag does not change the Nelson file layout.

The saved file contains a Nelson-owned figure payload stored in an HDF5/NH5 container. It is intended for reopening figures with openfig, including their graphics object tree and supported persistent properties.

Warning: Nelson .fig files are Nelson-specific. They are not compatible with .fig files that were not generated by Nelson, and Nelson does not guarantee that non-Nelson .fig files can be opened.

savefig stores complete figures. To export a bitmap or vector image for publication, use image export functions such as saveas when available. To save workspace variables, use data save functions instead.

Runtime-only values such as live graphics handles embedded in arbitrary properties and function handles are not restored as portable figure state.

💡Examples
Save the current figure and reopen it.
f = figure('Visible', 'off');
plot(1:5, [1 4 9 16 25]);
title('Quadratic data');
figfile = [tempname(), '_quadratic.fig'];
savefig(figfile);
close(f);
restored = openfig(figfile, 'invisible');
assert(isgraphics(restored, 'figure'));
close(restored);
Save with automatic .fig extension.
f = figure('Visible', 'off');
plot(1:3);
figfile = [tempname(), '_auto_extension'];
savefig(f, figfile);
assert(isfile([figfile, '.fig']));
close(f);
Save multiple figures in one file.
figs(1) = figure('Visible', 'off');
plot(1:4);
figs(2) = figure('Visible', 'off');
bar([2 4 3]);
figfile = [tempname(), '_two_figures.fig'];
savefig(figs, figfile);
close(figs);
restored = openfig(figfile, 'invisible');
assert(isequal(numel(restored), 2));
close(restored);
Use a version flag accepted for compatibility.
f = figure('Visible', 'off');
surf(peaks());
figfile = [tempname(), '_surface.fig'];
savefig(f, figfile, '-v7.3');
close(f);
🔗See Also
openfiggcfsaveassavenh5
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub