openfig()
openfig(filename)
openfig(filename, copies)
openfig(filename, visibility)
openfig(filename, copies, visibility)
fig = openfig(...)
| Parameter | Description |
|---|---|
| filename | Character vector or string scalar naming a Nelson .fig file. If filename has no extension, openfig appends .fig. The default is Untitled.fig. |
| copies | 'new' or 'reuse'. The default is 'new'. Use 'reuse' to return an already opened figure whose FileName property matches the requested file. |
| visibility | 'visible' or 'invisible'. This option overrides the saved visible state after the figure is restored or reused. |
| Parameter | Description |
|---|---|
| fig | Opened figure graphics object or array of figure graphics objects. If the file contains several saved figures, all restored figures are returned. |
openfig() opens Untitled.fig.
openfig(filename) opens the figure or figures stored in filename and creates new figure objects.
openfig(filename, 'new') always creates new figure objects. This is the default behavior.
openfig(filename, 'reuse') first searches opened figures whose FileName property matches the resolved file path. If such figures exist, they are returned instead of loading a new copy.
openfig(filename, visibility) or openfig(filename, copies, visibility) controls whether restored or reused figures are visible.
Each restored figure receives a FileName property equal to the resolved .fig path. This allows later calls with 'reuse' to find it.
Warning: Nelson .fig files are Nelson-specific. Files not generated by Nelson are not supported.
The restored objects are new graphics objects. Most persistent properties saved by savefig are restored, while current defaults and runtime-only state can still affect the newly created figures.
x = linspace(0, 10);
y = sin(x);
f = figure('Visible', 'off');
plot(x, y);
title('Sine Wave');
xlabel('x ranges from 0 to 10');
ylabel('y = sin(x)');
figfile = [tempname(), '_SineWave.fig'];
savefig(f, figfile);
close(f);
restored = openfig(figfile, 'invisible');
assert(isgraphics(restored, 'figure'));
close(restored);
f = figure('Visible', 'off');
plot(1:5);
figfile = [tempname(), '_visible_on_open.fig'];
savefig(f, figfile);
close(f);
restored = openfig(figfile, 'visible');
assert(strcmp(char(get(restored, 'Visible')), 'on'));
close(restored);
f = figure('Visible', 'off');
plot([3 1 4 1 5]);
figfile = [tempname(), '_reuse_example.fig'];
savefig(f, figfile);
close(f);
first = openfig(figfile, 'invisible');
second = openfig(figfile, 'reuse', 'invisible');
assert(isequal(first, second));
close(first);
figs(1) = figure('Visible', 'off');
plot(1:4);
figs(2) = figure('Visible', 'off');
stairs([4 2 3]);
figfile = [tempname(), '_many_figures.fig'];
savefig(figs, figfile);
close(figs);
restored = openfig(figfile, 'invisible');
assert(isequal(numel(restored), 2));
close(restored);
| Version | Description |
|---|---|
| 2.0.0 | initial version |