Main Content

Access Custom C Code in Library Models

You can integrate custom code written in C or C++ with Stateflow® charts in Simulink® models. By sharing data and functions between your custom code and your Stateflow chart, you can augment the capabilities of Stateflow and leverage the software to take advantage of your preexisting code. For more information, see Reuse Custom Code in Stateflow Charts.

Task 1: Include Custom C Code in Simulation Targets for Library Models

Specify custom code options in the simulation target for each library model that contributes a chart to the main model:

  1. In the Modeling tab, under Design, select Simulation Custom Code.

    The Configuration Parameters dialog box appears. Open the Simulation Custom Code pane.

  2. Select Use local custom code settings (do not inherit from main model).

    This step ensures that each library model retains its own custom code settings during simulation.

  3. Specify your custom code in the subpanes.

    Follow the guidelines in Specify Relative Paths to Your Custom Code.


    See Task 1: Include Custom C Code in the Simulation Target for descriptions of the custom code options.

  4. Click OK.

Task 2: Simulate the Model

Simulate your model by clicking the play button in the toolbar of the editor.

For information on setting simulation options using the command-line API, see Command-Line API to Set Simulation and Code Generation Parameters.


You cannot simulate only the Stateflow blocks in a library model. You must first create a link to the library block in your main model and then simulate the main model.

Related Topics