MATLAB: How to use variables from the GUI in the function

guisavevariableworkspace

I have a GUI with text boxes and pop up menus, but I'm having trouble trying to save the output variables and then using them within my function. I call upon the GUI in my function but the code executes before I even get to choose my options from the GUI! I'm not very familiar with GUIs some explanation would be appreciated! Thank you in advance.

Best Answer

Seems like you're using GUIDE?
You have to uncomment the uiwait(handles.figure1) in the OpeningFcn. Otherwise your GUI will close out before you can do anything. You also need to use uiresume in each Callback function to ensure your uiwait coding execution blockage is lifted.
To see an example, do the following:
1) >> guide
2) In guide setup, Create New GUI -> Modal Question Dialog -> OK
3) Look at the .m file for CloseRequestFcn, OpeningFcn, CallBack, OutputFcn