Converting the program to the GUI version

2 ビュー (過去 30 日間)
Darek Myszk
Darek Myszk 2018 年 11 月 14 日
コメント済み: Rik 2018 年 11 月 15 日
Hi. I have a problem because I've never used GUI before but now I must build GUI for my program. It consist of several stages: input datas from keyboard, generating matrices, two algoritms operating on created matrices. Now I have build something like this: Zrzut ekranu 2018-11-14 o 21.31.44.png
But, my 'code' to input dates and to making matrix is hooked to button 'Generowanie macierzy' as a function, and now when I want to make new event hook to button 'Macierz kontroli parzystosci' program can not see variable from another function.
How to make the program use data between functions?
Thanks for help

回答 (1 件)

Rik
Rik 2018 年 11 月 14 日
There are many ways to share data between callbacks. In the context of GUIs the most often used function is guidata.
You can also choose setappdata together with getappdata.
  2 件のコメント
Darek Myszk
Darek Myszk 2018 年 11 月 15 日
編集済み: Darek Myszk 2018 年 11 月 15 日
Hi. Can you take me tip how to use this? I Have a function hooked to one button, and I want to use variable from this function when a click on another button. I don't understand how to use this :/
Rik
Rik 2018 年 11 月 15 日
You should make sure to save that variable to your handles struct (with guidata), or to save it to the appdata.
In the callback to your first button, save it:
someVariable=rand;
handles.someVariable=someVariable;
guidata(handles.f,handles)
And then you can load it in your second callback:
if hasfield(handles,'someVariable')
someVariable=handles.someVariable;
else
error('someVariable was not assigned, run first button first')
end

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

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by