Generate and execute C and C++ code from Simulink models, Stateflow charts, and MATLAB functions for use in applications such as simulation acceleration, rapid prototyping, and hardware-in-the-loop (HIL) simulations
To generate C or C++ code from a model that represents a discrete-time system, use the Simulink Coder app. When you open the app, a C Code tab is added to the toolstrip. The C Code tab contains sections that represent steps of the Simulink Coder workflow. You can iterate through model preparation for code generation, code generation and builds, and code verification by using the editor window panels.
Use the app to:
Access help. On the left side of the Simulink® Editor window, click the Code Perspective Help tab.
Learn product basics while quickly configuring a model for code generation. If you are new to Simulink Coder™, use the Simulink Coder Quick Start to prepare a model for code generation. The Simulink Coder Quick Start chooses fundamental code generation settings based on your goals and application. To open the Simulink Coder Quick Start, click Quick Start.
Set code generation objectives and prepare a model for code generation. Click C/C++ Code Generation Advisor.
Configure model-wide code generation parameter settings. Click Settings.
Configure data. At the bottom of the editor window, click the Model Data Editor tab. On the left side of the editor window, click the Property Inspector tab.
Generate code or build an executable program. Select Build > Generate Codeor Build > Build.
Review generated code. Click Open Report.
Create a protected model for simulation and code generation to share with a third party. Select Share > Generate Protected Model.
Package generated code and artifacts for deployment to another computer system. Select Share > Generate Code and Package.
In the Apps gallery, under Code generation, click Simulink Coder. The C Code tab opens.
If you are working with a model hierarchy, open the Simulink Coder app in the Simulink Editor window for the top model of the hierarchy that you are generating code for. On the C Code tab, the functionalities apply to the top model of the hierarchy that is open in the editor.
To configure code for a referenced model, navigate to the model in the hierarchy and use the Model Data Editor and the Property Inspector. These views apply to the active model, which can be the top model or a referenced model.