Yet another create, numbered, figures with visible off

81 ビュー (過去 30 日間)
nanren888
nanren888 2020 年 7 月 11 日
編集済み: Chad Greene 2023 年 4 月 12 日
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 件のコメント
madhan ravi
madhan ravi 2020 年 7 月 11 日
編集済み: madhan ravi 2020 年 7 月 11 日
“How do you return to a figure without making it visible?”
By its handle.
nanren888
nanren888 2020 年 7 月 12 日
編集済み: nanren888 2020 年 7 月 12 日
Well thanks for the informative response. These forums are made or broken on the friendliness and usefulness of responses.

サインインしてコメントする。

回答 (2 件)

Adam Danz
Adam Danz 2020 年 7 月 11 日
編集済み: Adam Danz 2020 年 7 月 12 日
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 件のコメント
nanren888
nanren888 2020 年 7 月 12 日
編集済み: nanren888 2020 年 7 月 12 日
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 2020 年 7 月 12 日
編集済み: Adam Danz 2020 年 7 月 14 日
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
nanren888 2020 年 7 月 12 日
set(0,'CurrentFigure',fH) appears to select the figure, but not make it visible.

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by