GUI - How to differentiate the handles of the overall GUI vs. Callback function of each component?

1 回表示 (過去 30 日間)
YIMING
YIMING 2011 年 5 月 21 日
That is to say, every time when we create a MATLAB GUI, there will be a 'handles' in its opening function:
GUI_name_OpeningFcn(hObject, eventdata, handles, varagin)
I declared some global variables in the handles here. However, when we add some extra components to this GUI, for each Callback functions, there will be a local handles like:
function Button_Callback(hObject, eventdata, handles)
So my questions is, what if I want to use the global handles properties in the local Callback function? How do I differentiate two types of handles (i.e., global vs. local)?

回答 (2 件)

Daniel Shub
Daniel Shub 2011 年 5 月 21 日

Matt Fig
Matt Fig 2011 年 5 月 21 日
Don't name your global variable the same name as any local variable where it will be used. This is one of the problems with using global variables, and part of the reason their use is not recommended in general...
I.E., name your global variable something like: handle_global
  2 件のコメント
YIMING
YIMING 2011 年 5 月 22 日
Dear Sir, thanks for your comments. I'm wondering the difference between a global 'handles' and a local one, are they the same thing? Sharing the identical structure or something like that?
Matt Fig
Matt Fig 2011 年 5 月 22 日
Hello YIMING,
If you declared a global variable named handles like this:
global handles
then there exists a global variable named handles which is different than one that gets passed in to a function. I hope you are not mixing up terminology by calling the variable global...

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by