Main Content

Simulink Coder

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

Since R2019b

Description

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 Simulink® Editor 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:

  • 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 Advisor.

  • Configure model-wide code generation parameter settings. Click Settings.

  • Configure data. Select Code Interface > Default Code Mappings or Code Interface > Individual Element Code Mappings, which open the Code Mappings editor and Property Inspector.

  • Generate code or build an executable program. Select Build > Generate Code or 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.

Simulink Coder App

Open the Simulink Coder App

In the Apps gallery, under Code generation, click Simulink Coder. The C Code tab opens.

Tips

  • 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 data for a referenced model, navigate to the model in the hierarchy. Open the Code Mappings editor and Property Inspector by selecting Code Interface > Default Code Mappings or Code InterfaceIndividual Element Code Mappings. These tools apply to the active model, which can be the top model or a referenced model.

Version History

Introduced in R2019b