Running an m file by clicking on a pushbutton in GUI
Show older comments
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
6 Comments
devendra kaushal
on 1 Jan 2017
simple code
run myfile
Hong Nhat Vu
on 20 Feb 2017
Help me Sirs, I make a script with variables then i make a GUI with push button to call variables from the script m.file to workspace, but nothing happened when GUI running - variables not appear in Workspace. Thanks
Amit Patankar
on 27 Jan 2021
Same problem with me. Using run command, the *.m file runs very well but do not load the parameters in workspace.
Walter Roberson
on 28 Jan 2021
@Amit Patankar is the file you are using run() for a script or a function? If it is a script, then it makes changes to the workspace of the function or script that the call to run() appears in. Do not use run() to try to work with variables in the base workspace: use evalin('base') for that.
I have rarely found run() to be advisable. The only case that I have seen it used as an interesting design choice, had to do with a package that allowed the users to create "plug-ins". Designing infrastructure for plug-ins always involves design trade-offs.
Amit Patankar
on 28 Jan 2021
@Walter Roberson I am using a push button in App designer and in it's callback, I have written a Run command to run *.m files.
Just like when a *.m file is ran in command window of MATLAB and it loads all parameters into workspace, I expect that the push button should do it for me.
Walter Roberson
on 28 Jan 2021
Well, it is loading the parameters into the workspace -- the workspace of the callback function.
As I wrote above:
Do not use run() to try to work with variables in the base workspace: use evalin('base') for that.
Accepted Answer
More Answers (2)
Jan
on 28 Jun 2013
You can obtain the results created by your function simply by catching them as outputs:
Result = myfile;
This is completely the same as for calling sin(0.1), where you will store the results in an output also.
Any kind of remote controlled assignments of variables cannot compete with this clean and clear method.
4 Comments
daeze zezezeze
on 20 Jan 2018
how can I open a script file named incircle.m saved in this path : C:\Users\DOC\Desktop\Nouveau dossier\MinBoundSuite\incircle.m Thank you
Walter Roberson
on 20 Jan 2018
run('C:\Users\DOC\Desktop\Nouveau dossier\MinBoundSuite\incircle.m')
This relies upon you being correct that this is a script and not a function . If it is a function then you should
addpath('C:\Users\DOC\Desktop\Nouveau dossier\MinBoundSuite');
result = incircle(....)
Walter Roberson
on 10 Feb 2019
motevalizadeh comments
right
Margarita Diaz-Cortes
on 13 Feb 2020
Your reply just made my day, thank you so much!
Tonghui Zhang
on 9 May 2019
0 votes
Hi guys,
I am confronted with a similar problem. When I use run command in my GUI, it works well. But after I generated an exetutable program(exe), the run function report that the specified m file cannot be found. When I use a constant path to the run function. It reports that the m script cannot be executed. But the problem is that I can run it very well in guide. Are there anyone can help me?
Thanks a lot
2 Comments
Walter Roberson
on 13 May 2019
In another post we discussed that run is not permitted in compiled executables. You indicated that you were able to eval instead
Tonghui Zhang
on 13 May 2019
Yeah,
This is a previous question.
Categories
Find more on Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!