问题
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