How do I close a specific figure

248 views (last 30 days)
Nimrodb
Nimrodb on 25 Feb 2013
Commented: Laercio Barbosa on 21 Mar 2019
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).

Answers (4)

João Miguel Marinheiro
João Miguel Marinheiro on 21 Feb 2019
Edited: João Miguel Marinheiro on 21 Feb 2019
close(figure(<number of figure>))

Morteza
Morteza on 25 Feb 2013
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 on 25 Feb 2013
hFig = figure;
surf(peaks);
To close that figure:
close(hFig)
  3 Comments
Nimrodb
Nimrodb on 26 Feb 2013
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?

Sign in to comment.


Laercio Barbosa
Laercio Barbosa on 21 Jun 2017
Edited: Laercio Barbosa on 21 Mar 2019
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 Comments
Laercio Barbosa
Laercio Barbosa on 21 Mar 2019
@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);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by