I would like to generate the code via .m script from a simulink model.
Show older comments
Note : i am new to script , can u add the description in steps aswell
I have abc model and respective .m file to load all the parmeter .
Now i need to generate the code and publish in jenkins pipeline.
i need to run the run the script calling the matlab model and respective parameter files to generate the code.
I tried withthis .bat file calling the .m file in jenkins but its taking much time and code gen is also not happening.
%.bat file%
PATH=%MATLAB_HOME_2021%\bin;%PATH%
matlab.exe -nodesktop -nosplash -r "run('./abc.m');exit" -wait -logfile logfile
REM To remove the build folder created for matlab execution
:://RD /S /Q "slprj"
%.m file%
run('abc_StartUp.m');
warning('off','all')
%generate code
try
open_system('abc.slx')
rtwbuild('abc')
catch
end
end
clear;
**************************
Did my above file content is correct , can anyone support on this.
Answers (1)
Venkat Siddarth Reddy
on 11 Sep 2024
Edited: Venkat Siddarth Reddy
on 11 Sep 2024
0 votes
Hi Poornachandran,
Here I am assuming, "code generation not happening" as, there is no error and the BAT file is being executed indefinitely.
Based on this assumption, following are the few optimization I was able to identify in the M-script:
- Instead of "open_system" function you can use "load_system" to load the model, since "open_system" not only loads the model but also tries to open it. Using "load_system" may remove any unneccessary computation in MATLAB which is running with no desktop option.
- In the M-script, 'rtwbuild' function is used to generate the code, however, according to MATLAB documentation it is recommended to use 'slbuild' instead of 'rtwbuild' to generate the function.
To learn more about load_system, "rtwbuild" and its recommendation, please refer to the following documentation:
- rtwbuild's recommendation: https://www.mathworks.com/help/rtw/ref/rtwbuild.html
- load_system: https://www.mathworks.com/help/simulink/slref/load_system.html
Regards
Venkat Siddarth V
Categories
Find more on Introduction to Installation and Licensing 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!