How to get the handles of all open App Designer apps (uifigures)?

↘锁芯ラ 提交于 2019-12-11 12:03:47

问题


As mentioned in a related answer, it is possible to get the handles of all open figures using:

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

but this results in a list that contains both "old" figure and "new" uifigure handles.

How can I separate hFigs into two lists, one containing only figure and the other only uifigure references?


回答1:


To distinguish between figure and uifigure objects programatically, we can use a slight adaptation of what I suggested here:

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

It's advised to have a couple of warnings turned off before calling the above, e.g.

% 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);

and to conclude:

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

This solution was tested on R2017a and R2017b.



来源:https://stackoverflow.com/questions/47431214/how-to-get-the-handles-of-all-open-app-designer-apps-uifigures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!