6

有没有办法知道在matlab中打开了多少个数字?

4

2 回答 2

8

采用:

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

您还可以使用 @triazotan 建议的内容,使用findobj函数。但是它会更慢,因为您需要遍历所有对象。

编辑: 我决定看看findobj是如何工作的。这是遍历get(0,'Children')中所有对象的一种更复杂的方法
这是从findobj调用的文件中的小摘要:查看内置函数('get', 0, 'ShowHiddenHandles ' )本质上是中间的get(0,'Children') :

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显然是大材小用。

于 2012-01-09T14:49:59.323 回答
3

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

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

(即计数返回的图形句柄数findobj

于 2012-01-09T14:40:55.900 回答