I would like to generate the code via .m script from a simulink model.

5 次查看(过去 30 天)
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.

回答(1 个)

Venkat Siddarth Reddy
编辑:Venkat Siddarth Reddy 2024-9-11
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:
Regards
Venkat Siddarth V

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by