1

相关答案中所述,可以使用以下方法获取所有打开图形的句柄:

hFigs = findall(groot, 'Type', 'figure');

但这会产生一个包含“旧”figure和“新”uifigure句柄的列表。

我怎样才能hFigs分成两个列表,一个 figure包含引用,另一个 uifigure包含引用?

4

1 回答 1

2

为了以编程方式区分figureuifigure对象,我们可以稍微修改一下我在此处建议的内容:

function tf = isUIFigure(hFigList)
  tf = arrayfun(@(x)isstruct(struct(x).ControllerInfo), hFigList);
end

建议在调用上述之前关闭几个警告,例如

% Turn off warnings:
ws(2) = warning('query','MATLAB:structOnObject');
ws(1) = warning('query','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');
for indW = 1:numel(ws)
  warning('off', ws(indW).identifier);
end
% Call function:
tf = isUIFigure(hFigs);
% Restore the warnings' state:
warning(ws);

并得出结论:

hFigs = findall(groot, 'Type', 'figure');
isUIF = isUIFigure(hFigs);
hNewFigs = hFigs(isUIF);
hOldFigs = hFigs(~isUIF);

此解决方案在 R2017a 和 R2017b 上进行了测试。

于 2017-11-22T09:39:53.787 回答