Is there a way to know how many figures are opened in matlab?
clr performs: clear all; close all; clc; This clears your workspace, closes all figures, and clears command window.
To display values for a data point, drag the cross hairs to a specific point on the figure or move the figure by zooming and panning. The application retrieves the values and displays them.
Answer: If the program has any open windows, files, or tabs, press Ctrl+F4 or Ctrl+W to close them one at a time and keep the program open. Pressing the Esc key often closes or resizes any window, dialog box, or another element that does not have a close button.
Clear Figure and Reset Figure Properties clf reset resets all properties of the current figure, except for the Position , Units , PaperPosition , and PaperUnits properties.
Use:
numel(get(0,'Children'));
You can also use what @triazotan suggested, using the findobj function. However it will be slower, because you need to go through all of your objects.
Edit:
I've decided to see how findobj works exactly. It is a much more complicated way of going through all of the objects in get(0,'Children')
Here is small digest from the file that is being called from findobj:
Check out the builtin( 'get', 0, 'ShowHiddenHandles' ) which is essentially a get(0,'Children') in the middle:
function h = findobjhelper( varargin )
%Copyright 2009-2010 The MathWorks, Inc.
allowHVHandles = true;
nin = nargin;
rootHandleVis = builtin( 'get', 0, 'ShowHiddenHandles' );
% See if 'flat' keyword is present
hasflat = false;
if (nin > 1)
if strcmp( varargin{2}, 'flat' ) % Does the 'flat' keyword exist
hasflat = true;
end
end
if nin == 0
if feature('HgUsingMatlabClasses')
h = findobjinternal( 0, '-function', @findobjfilter );
else
h = findobjinternal(0);
end
Thus, using findobj is clearly an overkill.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With