Using a callback function which accesses two handles

Hello, here is the problem: my function creates two figures. The first figure contains a radio button, which callback function I would like to access both figures' data.
The code is something like this:
h=figure(...'tag',h);
parametres = uipanel(..);
h2=figure(...'tag',h2);
uicontrol('Parent',parametres,'Style','radiobutton','String','Pa','Units','pixels','Position',[240 95 120 15],'BackgroundColor','white','tag','bouton_Pa','Callback',@bouton_Pa_Callback,'KeyPressFcn',@key_bouton_PaetdB);
The callback function is :
function bouton_Pa_Callback(hObject,event)
%I tried using h2 as an input for the function, like (hObject,event,h2), didn't work
handles = guidata(gcbf);
handles2 = guidata(h2); % *This is where I get an error*
Apparently, gcbf can get the handle of the figure the button is located in (h), but if I try to get the data from h2 (which I believe to be the handle of the second figure), I get:
Undefined function or variable 'h2'.
How can I access the handle of a figure when I'm coding inside the callback function of a button located in another figure? I read that you could store and retrieve data from the GUI with getappdata and setappdata, but that would require me to "manually" create a variable containing all the figures' data, which is exactly what guidata is supposed to do, no?
Thanks :)

 採用された回答

per isakson
per isakson 2014 年 5 月 12 日
編集済み: per isakson 2014 年 5 月 12 日

1 投票

A problems is that there are so many different ways.
One way is to use the property Tag in combination with findobj. Thus
the_other_figure_handle = findobj( 0, 'Type','Figure' ...
, 'Tag' ,'a_good_name' );

3 件のコメント

Pascal
Pascal 2014 年 5 月 13 日
Thanks, it works.
Would declaring all the handles as global variables have helped?
per isakson
per isakson 2014 年 5 月 13 日
編集済み: per isakson 2014 年 5 月 13 日
Yes, but don't make it a habit to use globals. I guess, globals and the tag-findobj approach are ok only with small programs.
Pascal
Pascal 2014 年 5 月 13 日
In that case, what solution would you have recommended for large programs dealing with multiple GUI figures, in which the callback functions had to access a lot of data from different figures?

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

2014 年 5 月 12 日

コメント済み:

2014 年 5 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by