Yet another create, numbered, figures with visible off
Afficher commentaires plus anciens
I have a loop.
reuses figures, as matlab grinds to a halt with too many figures open.
Currently by numbering
inside for loop
figure(3)
plot,
print
end loop
.
Now sick of figures poping up, would like to get on with other things, want to make "visible","off"
figure(k,'Visible",'Off');
--> Numeric figure handles not supported with parameter-value pairs.
Message is clear enough. Annoying enough. Seems no particular reason for not allowing it.
.
Can obviously create handles, save handles and reuse handles, but that's way more messy than just numbering.
Any elegant suggestions?
3 commentaires
madhan ravi
le 11 Juil 2020
Modifié(e) : madhan ravi
le 11 Juil 2020
“How do you return to a figure without making it visible?”
By its handle.
Réponses (2)
You can use a 2-liner.
f = figure(1);
f.Visible = 'off';
Or, you could put it into a function so that you can use a 1-liner (that references a 2-lined function).
function h = invisibleFig(n)
% n is a positive integer
h = figure(n);
h.Visible = 'off';
end
now create a new figure with
invisibleFig(1)
Alternatively, don't specify the figure number and use the figure handle instead. This is almost always the better approach.
h = figure('Visible','off');
Recap
Try each section below to become familiar with these methods. The key is to use the figure handle (h, in my lines below).
To create a figure,
h = figure();
To create an invisible figure,
h = figure('Visible','off');
To set the visibility on,
h.Visible = 'on'; % = 'off' to turn back off
% or
set(h, 'Visible', 'on') % or 'off' to turn back off
To make a figure current,
figure(h)
% or
set(0,'CurrentFigure',h)
If you want to control the figure number and the visibility you must do that in two lines. However, it's rarely necessary to control the figure number. Use the figure handle instead.
h = figure(1);
h.Visible = 'off'; % or 'on' to turn back on
Lastly, and importantly, use the figure handle to specify a parent of an axes or any other object being added to the figure.
Example:
h = figure();
ax = axes(h);
2 commentaires
Sounds like you're working in circles and missing the point :)
I added a "recap" section to my answer to walk you through several options to manipulate the visibility of figures and control which figure is current. If there's something I'm missing, I'd be glad to help further.
nanren888
le 12 Juil 2020
0 votes
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!