How to get parent name of a child GUI component?

10 ビュー (過去 30 日間)
Khanh
Khanh 2014 年 10 月 20 日
コメント済み: Khanh 2014 年 10 月 21 日
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
  1 件のコメント
Khanh
Khanh 2014 年 10 月 21 日
Great. Thank you so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by