how can I determine the number of axes that a figure has?
using get(figure,'Children') works but also gives data on non-axis children, which I don't want

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 4 月 10 日

4 投票

Do you only want axes that are immediate children, or do you want all axes, even those that might be several objects down (such as within uipanel) ? And how about if the handles are hidden, do you want them returned or not?
Immediate children only:
findobj( get(gcf,'Children'), '-depth', 1, 'type', 'axes')
All children (including hidden) at all levels:
findall(gcf, 'type', 'axes')

5 件のコメント

Daniel Shub
Daniel Shub 2012 年 4 月 10 日
I much better answer than mine. A little text goes a long way.
Art
Art 2012 年 4 月 10 日
Thanks, this is close, but on the figures I have this always gives me one more handle than I expect.
Is it also returning a handle to the legend perhaps? what other "axes" possible (1 layer deep) are there on a figure?
Daniel Shub
Daniel Shub 2012 年 4 月 10 日
Both legends and colorbars are axes. There maybe other things that show up as axes. You can eliminate them on a case by case basis ...
findobj(gcf, 'type', 'axes', '-not', 'tag', 'legend', '-not', 'tag', 'Colorbar')
Art
Art 2012 年 4 月 11 日
that works - thanks
Massimo Ciacci
Massimo Ciacci 2021 年 11 月 16 日
Awesome tip, didn't know about '-depth'. Works a charm.

サインインしてコメントする。

Daniel Shub
Daniel Shub 2012 年 4 月 10 日

0 投票

findobj(gcf, 'type', 'axes')

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

質問済み:

Art
2012 年 4 月 10 日

コメント済み:

2021 年 11 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by