如相关答案中所述,可以使用以下方法获取所有打开图形的句柄:
hFigs = findall(groot, 'Type', 'figure');
但这会产生一个包含“旧”figure
和“新”uifigure
句柄的列表。
我怎样才能hFigs
分成两个列表,一个只 figure
包含引用,另一个只 uifigure
包含引用?
如相关答案中所述,可以使用以下方法获取所有打开图形的句柄:
hFigs = findall(groot, 'Type', 'figure');
但这会产生一个包含“旧”figure
和“新”uifigure
句柄的列表。
我怎样才能hFigs
分成两个列表,一个只 figure
包含引用,另一个只 uifigure
包含引用?
为了以编程方式区分figure
和uifigure
对象,我们可以稍微修改一下我在此处建议的内容:
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 上进行了测试。