Using:
numel(get(0,'Children'));
You can also use what @triazotan suggested using the findobj function. However, this will be slower because you need to go through all your objects.
Edit: I decided to see how findobj works. This is a much more complicated way to go through all the objects in get (0, "Children")
Here is a small digest from the file that is called from findobj : Check the built-in ('get', 0, 'ShowHiddenHandles') , which essentially is 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
So using findobj is clearly redundant.
source share