How to get the object handle?

26 次查看(过去 30 天)
'axes_of_data' is the child object of 'figure' and figure is the current figure.
Then can I use the following code to get the handle of 'axes_of_data'?
Note:There are two axes in the figure.'axes_of_data'is one of them.
h = findobj(gcf,'Children','axes_of_data');
But why it returns an empty matrix?

采纳的回答

Walter Roberson
Walter Roberson 2013-2-22
The value of 'Children' properties are always object handles (usually in handle graphic numeric form), and are never strings.
Is 'axes_of_data' a variable name, or is it a field in your handles structure, or is it the Tag of the axes? (The last two could potentially be both true, especially if you are using GUIDE.)
If it is a Tag, then use
h = findobj(gcf, 'Tag', 'axes_of_data')
  2 个评论
QiQin Zhan
QiQin Zhan 2013-2-22
Well,I've test it.Your code work well in the Callback Function.But when I put it in the subfunction of the Callback Function,it seems that it still returns an empty matrix? I'm confused.
Walter Roberson
Walter Roberson 2013-2-22
Is the gcf in fact returning the figure you expect?
Is the callback associated with a control on the same figure as you want to find the axes in? If so then if hObject is the name you gave to the first parameter to the callback, then
thisfig = ancestor(hObject, 'figure');
and then you would use
h = findobj(thisfig, 'Tag', 'axes_of_data');
You also need to consider the possibility that the axes has a hidden handle. By default, hidden handles are visible to findobj() within a callback associated with that handle, but are not visible to other callbacks. you can use findall() instead of findobj() if this might be interfering.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by