Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 879
YYC Avatar asked Oct 14 '10 23:10

YYC


People also ask

How do you get axes of a figure in Matlab?

ax = gca returns the current axes (or standalone visualization) in the current figure. Use ax to get and set properties of the current axes. If there are no axes or charts in the current figure, then gca creates a Cartesian axes object.

How do you find the handle of a figure in Matlab?

To get the handle of the current figure without forcing the creation of a figure if one does not exist, query the CurrentFigure property on the root object. fig = get(groot,'CurrentFigure'); MATLAB® returns fig as an empty array if there is no current figure.

How do you make an AXE in Matlab?

First create two Axes objects and specify the positions. Display the box outline around each axes. Return the Axes objects as ax1 and ax2 . figure ax1 = axes('Position',[0.1 0.1 .


1 Answers

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'})) 
like image 199
Jonas Avatar answered Sep 25 '22 14:09

Jonas