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!
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.
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.
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 .
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'}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With