Clear Filters
Clear Filters

Using input from a gui in another function

4 views (last 30 days)
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.

Answers (2)

Abhishek Pandey
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

Mohammed Abdallatif
Mohammed Abdallatif on 9 Jul 2019

Categories

Find more on Environment and Settings 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!