Using input from a gui in another function
2 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Abhishek Pandey
on 15 Jul 2015
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 Comments
Mohammed Abdallatif
on 9 Jul 2019
It seems to be less praticial and to be avoided. Have a look here!
0 Comments
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!