2012-01-09 29 views

回答

8

用途:

numel(get(0,'Children')); 

可以也使用@triazotan建议的,使用findobj函数。但是它会变慢,因为你需要浏览所有的对象。

编辑: 我决定去看看findobj是怎么工作的。它是在的get(0,“孩子”)
这里是小从正在从findobj文件称为消化过的所有对象将会更加复杂的方式: 检查出内置( '得到',0, 'ShowHiddenHandles')这基本上是一个的get(0, '儿童')的中间位置:

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 

因此,使用findobj显然是一个矫枉过正。

3

我不知道任何直接的方式,但你可以尝试:

length(findobj('Type','figure')) 

(图中即计数处理由findobj返回)

相关问题