Using input from a gui in another function
2 ビュー (過去 30 日間)
古いコメントを表示
So, I have a program that consists of many function files and one main .m file and .fig file.
I have a certain text box in the GUI and and button, and when the button is clicked, it stores the value of the text box in a variable in the main .m file using handles.
The question I have is, how do I use this value/variable in another function (not the main .m file)? Its basically a user_function that the user can change values by typing new ones in the GUI.
0 件のコメント
回答 (2 件)
Abhishek Pandey
2015 年 7 月 15 日
Hello Shawn,
I understand that you want to use the value of a text box in the GUI in another function. To do this, you can get a handle to the text box through the 'handles' structure and pass it as an input argument when you call the function.
For example, to get a handle for the text box (Tag : ‘txtbox1’), and passing it into the user function (say, userfunc), you can use the following lines of code:
hTxt = handles.txtbox1;
userfunc(hTxt);
Inside ‘userfunc’, you can get and set the value of the text box.
To get its value and store it in a new variable ‘c’,
c = str2num(hTxt.String);
To set its value to 45,
hTxt.String = num2str(45);
For more information, refer to this link:
I hope this helps!
- Abhishek
0 件のコメント
Mohammed Abdallatif
2019 年 7 月 9 日
It seems to be less praticial and to be avoided. Have a look here!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!