Automating Simulink Code Generation from DOS Command Window

25 views (last 30 days)
First, I am relatively a newbie for MatLab and Simulink - surrounded by very smart ME's writing very cool stuff.
What I want to do is take all of the manual point and click and turn this into a batch file to run from a DOS Command Window in order to load the models and generate the code for all of the models.
What I am attempting to create is an automated build script to run at night in batch mode. Pull all code from our Configuration Management tool, build all models, and then compile.
I am using MatLab 2011b, Simulink Coder, and TI Code Composer 5 (Eclipse)
Can someone point me at a tutorial or instructions on how to do this. I have been searching for answers to this question for a while and finally decided to just ask the question.
Thank you in advance.
David Clark LORD Corporation
  1 Comment
Mady J
Mady J on 4 Sep 2018
Hello David, My scenario is also same as yours. I need to know is there any document or website from where i can get complete list of windows command for matlab and simulink code generation.
Thank you Mady

Sign in to comment.

Accepted Answer

LIANG
LIANG on 20 Dec 2011
Hi David,
If you want to turn off the GUI and pop up window, try to run the dos command below options:
> start matlab -nosplash -nodesktop -minimize -noFigureWindows -r <matlab script>
To create a log file, add:
-logfile .\logfile.log
Btw, for those functions to open/close the model in your m-script, you need to add quotation marks like this:
open_system('Model');
rtwbuild('Model');
close_system('Model');
exit
"exit" is to exit Matlab after code generation.
Good luck.
  2 Comments
Fangjun Jiang
Fangjun Jiang on 20 Dec 2011
The way it works is that you specify the model name once so you don't have to change it three times in case it needs to be changed.
Model='F14';
open_system(Model);
rtwbuild(Model);
close_system(Model);

Sign in to comment.

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 15 Dec 2011
There are many things involved. But at the high level, you just need to set up two things. Of course, all the related files, configurations, etc have to be tested. I think your question is primarily about how to set up the automation assuming you've been able to do individual task successfully.
  1. From DOS command, you can start MATLAB with the -r optoin. "MATLAB -r MyCodeGenRoutine" will start MATLAB and then run MyCodeGenRoutine.m automatically.
  2. In your MyCodeGenRoutine.m, basically you need three lines. "open_system(Model);rtwbuild(Model);close_system(Model)'
  3. If you have multiple models, than you can put the three lines in a loop. After it's done, you can use "exit" command to close MATLAB.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!