How to get parent name of a child GUI component?

11 次查看(过去 30 天)
Hi everybody,
I have a figure with 'Name' property: 'My figure' and 'Tag' property: 'figure1'.
In this figure, I have a push button with 'Name' property: 'Push me' and 'Tag' property: 'pushbutton1'
How can I get the push button's parent name in a programmatic GUI?
Is its parent name 'Myfigure' or 'figure1'?
% Code generated by FIG2M made by Thomas Montagnon (The MathWorks France)
% Great thanks to him
% --- FIGURE -------------------------------------
handles.figure1 = figure( ...
'Tag', 'figure1', ...
'Units', 'characters', ...
'Position', [102.8 24.3076923076923 114 32.9230769230769], ...
'Name', 'figure1', ...
'MenuBar', 'none', ...
'NumberTitle', 'off', ...
'Color', [0.941 0.941 0.941]);
% --- PUSHBUTTONS -------------------------------------
handles.pushbutton6 = uicontrol( ...
'Parent', handles.figure1, ...
'Tag', 'pushbutton6', ...
'Style', 'pushbutton', ...
'Units', 'characters', ...
'Position', [13.4 22.9230769230769 24.4 1.92307692307692], ...
'String', 'Push Button');
a=get(handles.pushbutton6,'parent') % a is a double, I don't know how to get parent name from it.

采纳的回答

Orion
Orion 2014-10-20
Hi,
Actually, more than a double, a is a handle. (try ishandle(a))
In your case, with
a=get(handles.pushbutton6,'parent')
a is the handle of the parent of handles.pushbutton6, which here is the figure.
And to get the name of this (which usually is different of the tag) :
get(a,'Name')
ans =
figure1

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by