Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out how many figures are currently opened?

Is there a way to know how many figures are opened in matlab?

like image 377
Oli Avatar asked Jan 09 '12 14:01

Oli


People also ask

What is the command for closing all opened figures in MATLAB?

clr performs: clear all; close all; clc; This clears your workspace, closes all figures, and clears command window.

How do you show figures in MATLAB?

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.

Which command is used to close all the open figure windows?

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.

What does CLF mean in MATLAB?

Clear Figure and Reset Figure Properties clf reset resets all properties of the current figure, except for the Position , Units , PaperPosition , and PaperUnits properties.


1 Answers

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.

like image 112
Andrey Rubshtein Avatar answered Oct 15 '22 05:10

Andrey Rubshtein