Matlab: How to obtain all the axes handles in a figure handle?

YYC picture YYC · Oct 15, 2010 · Viewed 50.8k times · Source

How do I obtain all the axes handles in a figure handle?

Given the figure handle hf, I found that get(hf, 'children') may return the handles of all axes. However, the Matlab Help suggests that it may return more than just the axes handles:

Children of the figure. A vector containing the handles of all axes, user-interface objects displayed within the figure. You can change the order of the handles and thereby change the stacking of the objects on the display.

Is there any way to obtain only the axes handle in the figure handle? Or how do I know if the handle returned by get(hf, 'children') is an axe handle?

Thanks!

Answer

Jonas picture Jonas · Oct 15, 2010

Use FINDALL:

allAxesInFigure = findall(figureHandle,'type','axes');

If you want to get all axes handles anywhere in Matlab, you could do the following:

allAxes = findall(0,'type','axes');

EDIT

To answer the second part of your question: You can test for whether a list of handles are axes by getting the handles type property:

isAxes = strcmp('axes',get(listOfHandles,'type'));

isAxes will be true for every handle that is of type axes.

EDIT2

To select only axes handles that are not legends, you need to cleanup the list of axes (ax handles by removing all handles whose tag is not 'legend' or 'Colorbar':

axNoLegendsOrColorbars= ax(~ismember(get(ax,'Tag'),{'legend','Colobar'}))