如何获取所有打开的App Designer应用程序(uifigures)的句柄?

时间:2017-11-22 09:39:54

标签: matlab matlab-figure handle object-reference matlab-app-designer

related answer中所述,可以使用以下方式获取所有未结数字的句柄:

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

但这导致列表包含" old" figure和" new" uifigure处理。

如何将hFigs分成两个列表,一个仅包含 figure,另一个 uifigure个引用?< / p>

1 个答案:

答案 0 :(得分:2)

要以编程方式区分figureuifigure个对象,我们可以稍微调整一下我的建议here

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上测试该溶液。