Can we generate C++ code from Simulink models from bash or PowerShell command line?

2 vues (au cours des 30 derniers jours)
Sina Nejati
Sina Nejati le 19 Sep 2022
Modifié(e) : colordepth le 19 Jan 2025
Can we generate C++ code from Simulink models from bash or PowerShell?
I am a beginner with Matlab and Simulink, I manage the build system for my company, we are trying to integrate a build step that will look at all the Simulink models and generates code for them. In order to achieve that, we need an interface to Simulink Coder from the command line and not inside Matlab or it's add on applications.
Is this interface exposed ? and would this be a possibility ?

Réponses (1)

colordepth
colordepth le 19 Jan 2025
Modifié(e) : colordepth le 19 Jan 2025
You can execute matlab code non-interactively using the command line with the "-batch" commandline option. Create a MATLAB script "generate_code.m" like this:
model = 'your_model_name';
load_system(model);
slbuild(model); % Code generation using Simulink Coder
You can modify this MATLAB script to read model file paths from a .TXT file and build them in a loop. Run this script non-interactively in your shell with:
matlab -batch "generate_code"
For more details, see:
  1. MATLAB startup options: https://www.mathworks.com/help/releases/R2022b/matlab/matlab_env/commonly-used-startup-options.html
  2. "slbuild" documentation: https://www.mathworks.com/help/releases/R2022b/simulink/slref/slbuild.html.

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by