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 CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by