MATLAB: Running an m file by clicking on a pushbutton in GUI

guiguidem-fileMATLABpushbuttonrun m filerunning

Hiya,
I'm making a GUI using GUIDE and I want it to run a different file when i press a push button.
The file itself runs a few other files when it's run and gives an output of a series of variables with their values.
I was hoping I would be able to load and display these values in the GUI by running the file, and then be able to edit the values (still in the GUI).
Then, by pressing another pushbutton the GUI calls the file to calculate it's outputs using the updated variables and displays it.
I've tried using
run('myfile.m')
in the pushbutton callback, but the workspace isnt updated, so I'm not sure if it's actually being run or not.
alternatively I could call the GUI from the file, but I don't know how to do this either
Any help would be brilliant
Thanks

Best Answer

To run a m-file from a GUI, just insert the name of the m-file in the pushbutton callback function. It works the other way around. To open a GUI from a m-file, just type the name of the GUI in the m-file.
If you want your GUI to display values calculated within the m-file, you could define variables as global in both the GUI and the m-file.
If what you want is to display/send values to the workspace, you could use
assignin
from both your GUI or you m-file.
type
help assigin
or
doc assigin
in the command window to get all the information about the assigin built-in function.
Related Question