Borrar filtros
Borrar filtros

Using input from a gui in another function

4 visualizaciones (últimos 30 días)
Shawn Castelino
Shawn Castelino el 11 de Jul. de 2015
Respondida: Mohammed Abdallatif el 9 de Jul. de 2019
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.

Respuestas (2)

Abhishek Pandey
Abhishek Pandey el 15 de Jul. de 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 el 9 de Jul. de 2019

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by