Filter löschen
Filter löschen

Using input from a gui in another function

4 Ansichten (letzte 30 Tage)
Shawn Castelino
Shawn Castelino am 11 Jul. 2015
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.

Antworten (2)

Abhishek Pandey
Abhishek Pandey am 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 am 9 Jul. 2019

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by