openfig visibility when saved figure has a callback
Ältere Kommentare anzeigen
I used the method described here to save figures with a callback that would change their visibility to 'on' when opened.
fig = figure('Visible','off');
set(fig, 'CreateFcn', 'set(gcbo,''Visible'',''on'')');
plot([1:10]);
savefig(fig,"C:\temp\test.fig")
close all
openfig("C:\temp\test.fig",'invisible')
Behavior of sample code: figure opens and is visible
Desired Behavior: figure opens and is invisible.
Is this possible? Thank you.
5 Kommentare
dpb
am 15 Aug. 2025
What is the callback function definition you are using?
Walter Roberson
am 15 Aug. 2025
Bearbeitet: Walter Roberson
am 15 Aug. 2025
Are you hooking into one of the Create* callbacks?
Are you using GUIDE or App Designer or plain savefig() ?
Max Frantz
am 18 Aug. 2025
dpb
am 19 Aug. 2025
You still haven't answered the questions posed -- show the exact code you are using for the callback function.
If you just copied the example referenced, it specifically was for the reverse situation where a figure was saved as 'invisible' and the user wanted it to be automagically made visible on loading.
You're after the opposite, so if you used the same callback function, that's where the 'on' is coming from--but, you haven't shown us the actual code, just tried to describe it and symptoms.
The best would be to post a minimum working example that creates the problem by extracting the pertinent code from the app....but, specifically, the callback function code itself is needed...and, wouldn't hurt to attach an example image file just to be certain folks have the same set of conditions with which to experiment if so inclined...
Max Frantz
am 19 Aug. 2025
Akzeptierte Antwort
Weitere Antworten (2)
Ritika Thusoo
am 18 Aug. 2025
Hi,
You can use the ‘openfig(___,visibility)’ to specify whether to open the figure in a visible or invisible state. To display the figure, set visibility to 'visible'. If you do not want to display the figure, use the 'invisible' setting.
Sample code:
fig = openfig('MySavedPlot.fig', 'invisible');
% Create a figure and set it to be invisible
f = figure('Visible', 'off');
plot(sin(linspace(0, 2*pi, 100))); % Example plot
savefig(f, 'MySavedPlot.fig'); % Save the figure
close(f); % Close the figure
% Open the saved figure with visibility set to 'off'
fig = openfig('MySavedPlot.fig', 'invisible');
fig.Visible = 'off'; % Make the figure visible
% Make the fig.Visible = ‘on’ in case you wish to make the figure visible.
You can read about this further from the following ‘openfig’ documentation page: https://www.mathworks.com/help/releases/R2025a/matlab/ref/openfig.html
1 Kommentar
Max Frantz
am 18 Aug. 2025
Ken
am 4 Mär. 2026 um 14:15
0 Stimmen
I was having the exact same issue and this seemed to work for what I needed. It overwrites the callback function prior to opening:
hgload("C:\temp\test.fig", struct('CreateFcn', '', 'Visible', 'off'));
Kategorien
Mehr zu Programming Utilities finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!