I'm trying to write a code in my .m/ GUI file that can pass a certain value obtained from an "edit text" field (called "edit 1") in GUI when I press a push button - to a .m file. Say in the GUI I have this: GUI example What I want to do is to get the value inputted on the "fc'" and "slump" field and use it in a mathematical operation in a .m file. In the GUI, I've written the code to run my m file below the "calculate" pushbutton callback, and in my .m file, I've written:
value = str2num(get(handles.edit1,'String'));
In return, I get Undefined variable "handles" or class "handles.edit1" when I run the UI. What should I write in my .m file or perhaps the GUI editor to obtain the values?
Any solutions/ help would be very much appreciated. Thanks!
Programmatically Creating GUI and Callback Functions
Not sure how open you are to doing it programmatically but here is a setup that grabs the values of the fields and uses them in a callback function called
Calculate(). Another callback function that clears the field is calledReset(). Below is the GUI and the inputs of the callback functions printed in the command window:The callback function is triggered when the buttons are pressed indicated by the
.ButtonPushedFcnproperty being set to the corresponding function that needs to run.Full Script:
Ran using MATLAB R2019b