I solved this by simply updating the models to MATLAB 2015a, setting the "Reusable Code" flag, saving, and then compiling by simply calling "matlab -r rtwbuild(model)". No need to deal with options via command-line in MATLAB 2015a.
How to make RTW options persist.
5 views (last 30 days)
Show older comments
Sergey Ponomarev
on 28 Mar 2017
Answered: Sergey Ponomarev
on 24 May 2017
When compiling a Simulink model with RTW (r2013a), I need to check "Code Generation > Interface > Code Interface > Generate reusable code" every time I open the model. I would like to automate my building and so I either need to have this option saved in the model, or drive it from the command-line before building.
This is the only parameter that doesn't seem to be saved in the model. Others like "System target file" save just fine and I don't need to reset them. My guess is that this is a bug in my version of Matlab (r2013a).
So my next question is: How can I over-drive this parameter from the command line? My current method of running this model is:
matlab ^
-nojvm ^
-nodisplay ^
-nodesktop ^
-r "addpath('%modelpath%'); addpath('%tlcpath%'); addpath(genpath('%scriptpath%')); rtwbuild('%modelname%'); quit;" ^
-logfile %modelname%.log
It's possible that the long -r parameter can be turned into a .m file. I think I can set this with:
cs = Simulink.ConfigSet;
cs.set_param('MultiInstanceERTCode', 'on');
If I put it in my build-script it doesn't seem to do anything (probably because my model isn't open yet). If I save it in my "Model Properties > Callbacks > PostLoadFcn" it also doesn't seem to do anything.
Another thing I've tried is:
hCs = getActiveConfigSet('b737ng_yd_solenoid')
hCs.saveAs( 'ConfiguredDataScript', '-format', 'MATLAB script', '-varname', 'config_set')
I've done this before and after swapping the "Generate reusable code" and I do see the difference in the resulting script. However running the script before opening the simulink, or running the script with the simulink open will not restore this specific flag.
I am going to just try installing a new version of MATLAB to see if this is fixed in a later release.
0 Comments
Accepted Answer
More Answers (1)
Varun Gunda
on 6 Apr 2017
Edited: Varun Gunda
on 6 Apr 2017
You can use Simulink® Preferences to specify Simulink editing environment options and default behaviors.
In the MATLAB® Command Window, enter slprivate('showprefs')
Here change the preferences in Configuration Defaults > Code Generation > Interface.
This will change the default options.
References:
1 Comment
See Also
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!