How to use an external script/app to automatically start the matlab model without the user having to manually press the run button

Hi I'm hoping someone can help me..
I have created a complex model that incorporates many scripts and functions, and all of these are ran from a main script file.
I was wondering if it is possible to use an outside script or different application to start the main script file. My idea is to have a StartModel app that will run the matlab code automatically which would mean that the user would not have to open the script and manually press the run button.
Thank you, any help will be much appreciated.
Tadgh

Answers (2)

You can use callbacks in your GUI for this task. See for example http://www.mathworks.de/de/help/matlab/creating_guis/initializing-a-guide-gui.html.

3 Comments

I'm not sure if this will work for me. I have one script file that when running, calls many other scripts to calculate the required results.
I would ideally like a separate script or function that once selected to open automatically runs the Main.m script file. This would prevent the user from having to select to run the main script and would take the chances of the user running the wrong file.
I hope my explanation makes sense, thank you for your help.
I believe, that's exactly what you need: they are called Apps. See a short video on how to develop an App here.
In your case the App could be pretty simple, since you are only (at this point) would use it to run your main script, which, in turn, would call all the other scripts.
Great it seems you've put me on the right track. I've attempted to build a basic yes/no question box which will ask 'Do you want to run the renewable energy model?' but can find where to put in my ' run filename'. The autogenerated code is also trying to create a figure..
I understand that it will be very simple because all i want it to do is automatically run a script file, but i have never used the GUI interface before and time is against me :D Final year project and all that....
Thank you for your help

Sign in to comment.

Use the command line flags when MATLAB is invoked. For example create a .bat file that has
matlab.exe -r "try cd('C:\Appropriate\Directory'); NameOfScriptToStart; catch ME; end; quit"
Then the user would double-click the .bat file in order to launch NameOfScriptToStart .
Note: do not include the ".m" suffix in NameOfScriptToStart .

1 Comment

Great nearly there.. I've made a .bat using the standard notepad in windows, and used your code with the change
matlab.exe -r "try cd('C:\Appropriate\Directory'); Renewable_Energy_Model; catch ME; end; quit"
The Renewable_Energy_Model.m file is the file i am trying to run but at the moment when the .bat file is double clicked it just opens matlab for a few seconds and closes without doing anything?

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Asked:

on 13 Jan 2014

Commented:

on 15 Jan 2014

Community Treasure Hunt

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

Start Hunting!