How do I close a specific figure

조회 수: 101 (최근 30일)
Nimrodb
Nimrodb 2013년 2월 25일
댓글: Laercio Barbosa 2019년 3월 21일
I have a GUI. This GUI runs a simulation the at the end of it I open a figure to display results.
When I re-run the simulation - the old figure is kept open.
How do I close the old figure without closing the GUI?
('close all' close all the windows including the GUI).

답변 (4개)

João Miguel Marinheiro
João Miguel Marinheiro 2019년 2월 21일
편집: João Miguel Marinheiro 2019년 2월 21일
close(figure(<number of figure>))

Morteza
Morteza 2013년 2월 25일
In the section of simulation use these line:
handles.H = figure(2)
plot(rand(10,1));
waitforbuttonpress;
close(handles.H)
when you press any button ploter figure automatically will be closed

Sean de Wolski
Sean de Wolski 2013년 2월 25일
hFig = figure;
surf(peaks);
To close that figure:
close(hFig)
  댓글 수: 3
Sean de Wolski
Sean de Wolski 2013년 2월 25일
Then that handle hasn't been stored. You should store that handle in whatever is calling the simulation so that it can close it.
Nimrodb
Nimrodb 2013년 2월 26일
as a global in the beginning of the main function? The simulation is called from a GUI built by GUIDE.
The flow is:
GUI made by GUIDE --> Simulation ---> Results function (that opens a Figure)
Where and how do I save the figure handle?

댓글을 달려면 로그인하십시오.


Laercio Barbosa
Laercio Barbosa 2017년 6월 21일
편집: Laercio Barbosa 2019년 3월 21일
I am passing here to let my contribution as I had exactly the same problem. If you know the name or tag of the GUI do:
% Close all figures still openned except the GUI which property 'name' is equal 'nameOfQUI'
figHandles = findobj('type', 'figure', '-not', 'name', 'nameOfGUI');
close(figHandles);
or
% Close all figures still openned except the GUI which property 'tag' is equal 'tagOfQUI'
figHandles = findobj('type', 'figure', '-not', 'tag', 'tagOfGUI');
close(figHandles);
  댓글 수: 2
beginner94
beginner94 2018년 9월 16일
@Laercio Barbosa
You only need to fill in ''tag'' and ''tagOfGUI'', right? So if the tag of my GUI is ''figure1'', then:
figHandles = findobj('type', 'figure', '-not', 'figure1', 'figure1');
close(figHandles);
should do it? It doesn't work for me and I am searching for my error...
Laercio Barbosa
Laercio Barbosa 2019년 3월 21일
@beginner94, sorry for the late response.
No. You don't need fill all the fields you mentioned. Only the last one. Basically what we are doing is:
Find objects of type figure, but not that one where figure property is equal figure1.
or still
Find objects of type figure, but not that one where tag property is equal "tagname".
In your case
figHandles = findobj('type', 'figure', '-not', 'figure', 'figure1');
close(figHandles);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by