How to use variables in between GUI function?

9 ビュー (過去 30 日間)
chlor thanks
chlor thanks 2016 年 7 月 25 日
コメント済み: chlor thanks 2016 年 7 月 27 日
I am very new to GUI and so far for my understanding is that you can only put a tag's name behind handles. to communicate between different functions. For example, one uses axes(handles.axes1) inside a push button function.
For my case, I have several functions inside a GUI and there is one variable that is produced by one function, which is not defined previously when I made the GUI layout by GUIDE, it is only produced when the code is run and I would like to use it later in a pushbutton function, in this case, what should I do to make this variable outside of its mother function in order to be used in my pushbutton function?
Sorry if I sound confusing.
Any discussion/help is welcomed! Thanks!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 7 月 25 日
your_variable=10
handles.your_variable=your_variable
guidata(hObject,handles)
To call the variable
your_variable=handles.your_variable
  8 件のコメント
Adam
Adam 2016 年 7 月 27 日
Anything that changes non-graphics objects data on the handles struct will need a call to guidata after it in order to save it back into the main GUI.
If you have factored out a function from a callback or are using listeners you may not have 'hObject' though. In this case you can use gcbo instead or pass the handle of the main GUI down to your function and use
handles = guidata( hGUI );
to extract the handles struct, hGUI being the handle to your main GUI.
chlor thanks
chlor thanks 2016 年 7 月 27 日
This makes sense, thanks for the tips! I will keep them in mind.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by