How to find objects by number of children?

8 vues (au cours des 30 derniers jours)
Jakob Holz
Jakob Holz le 4 Mar 2022
Commenté : Jakob Holz le 4 Mar 2022
Hey Im trying to select only figures with a particular number of axes.
I got this far:
  • I have a list of all active figures via
figArray = findobj(groot, 'type', 'figure');
  • I could now of course filter this figure array using
for k = 1:length(figArray)
if length(get(figArray(k), 'children')) == 2
n = 1
validFigArray(n) = figArray(k)
n = n + 1;
end
end
How ever I would like to modify the findobj command so that it only returns figures with two axes.
Therefore I have tried this, with no success:
>> figs = findobj(groot, 'type', 'figure', '-and', 'children', '[2x1 Axes]');
>> figs = findobj(groot, 'type', 'figure', '-and', 'Children', '[2x1 Axes]');
>> figs = findobj(groot, 'type', 'figure', '-and', 'children', '[2x1]');
>> figs = findobj(groot, 'type', 'figure', '-and', 'children', '2');
Please tell me how I have to adjust the search parameters.
Thank you very much for your time and help.

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Mar 2022
There is no way to do that other than methods similar to what you are doing already. You could modify your flow though
figArray = findobj(groot, 'depth', 1, 'type', 'figure') ;
nax = arrayfun(@(F)length(findobj(F, 'type', 'axes')), figArray);
figArray = figArray(nax == 2);
If you are certain that the axes are direct children of the figures then you could put a depth restriction on the second findobj.
The use of findobj here is only appropriate for handle visibility on.
Historically colorbar and legend could show up as axes but should not these days.
I am not sure what happens with map axes.
  1 commentaire
Jakob Holz
Jakob Holz le 4 Mar 2022
Thank you very much Walter for taking time out of your day to help me.
People like you are invaluable for everybody how wishes to know more than they currently do.
I hope you have a pleasant day. Take care.
Regards Jakob

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by