Filter löschen
Filter löschen

Yet another create, numbered, figures with visible off

81 Ansichten (letzte 30 Tage)
nanren888
nanren888 am 11 Jul. 2020
Bearbeitet: Chad Greene am 12 Apr. 2023
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 Kommentare
madhan ravi
madhan ravi am 11 Jul. 2020
Bearbeitet: madhan ravi am 11 Jul. 2020
“How do you return to a figure without making it visible?”
By its handle.
nanren888
nanren888 am 12 Jul. 2020
Bearbeitet: nanren888 am 12 Jul. 2020
Well thanks for the informative response. These forums are made or broken on the friendliness and usefulness of responses.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Adam Danz
Adam Danz am 11 Jul. 2020
Bearbeitet: Adam Danz am 12 Jul. 2020
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 Kommentare
nanren888
nanren888 am 12 Jul. 2020
Bearbeitet: nanren888 am 12 Jul. 2020
Thanks for your reponse.
each time you use figure() it makes it visible again. Hiding it again, after visbile might work, I guess if the system didn't drawnow();
Use a handle?
I think that's what I did, when I tried, as in the comment.
The question is how do I return to it, to reuse it?
As above
fH = figure('Visible','off'): - works & returns a handle
But
figure(fH): - makes it visble again - so can't select the figure this way
And
figure(fH,'Visible','off'):
==>
Error using figure
Numeric figure handles not supported with parameter-value pairs.
So can't return to the figure this way.
.
I may be missing something obvious: hence the question. Happy to have someone tell me this.
.
I guess
(1) Maybe no way to do it elegantly, using figure(), eg need such as plot(ax, ....) which means changing every plot call :(
(2) set(0,'CurrentFigure',fH) ?
OK set(0,'CurrentFigure',fH) appears to select the figure, but not make it visible.
Adam Danz
Adam Danz am 12 Jul. 2020
Bearbeitet: Adam Danz am 14 Jul. 2020
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.

Melden Sie sich an, um zu kommentieren.


nanren888
nanren888 am 12 Jul. 2020
set(0,'CurrentFigure',fH) appears to select the figure, but not make it visible.

Produkte


Version

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by