Main Content

Access Custom Code Variables and Functions in Stateflow Charts

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 take advantage of your preexisting code. For more information, see Reuse Custom Code in Stateflow Charts.

Custom Code Variables in Charts That Use MATLAB as the Action Language

You can read and write the following C code variables directly in your charts that use MATLAB® as the action language.

Custom C Code TypeDescription
doubleDouble-precision floating point
singleSingle-precision floating point
int8Signed 8-bit integer
uint8Unsigned 8-bit integer
int16Signed 16-bit integer
uint16Unsigned 16-bit integer
int32Signed 32-bit integer
uint32Unsigned 32-bit integer

By right clicking on the Stateflow object that uses your custom code, you can access your custom code variable. After right clicking on the object, hover over Explore. Your custom code variable appears, denoted by (C variable). Clicking the C variable allows you to access the custom code from MATLAB.

Custom Code Functions in Charts That Use MATLAB as the Action Language

You can use the following C function argument types directly in your charts that use MATLAB as the action language without using coder.ceval. For information on calling external code from MATLAB code by using coder.ceval, see Call Custom C/C++ Code from the Generated Code (MATLAB Coder).

Custom C Function Argument TypeDescription
doubleDouble-precision floating point
singleSingle-precision floating point
int8Signed 8-bit integer
uint8Unsigned 8-bit integer
int16Signed 16-bit integer
uint16Unsigned 16-bit integer
int32Signed 32-bit integer
uint32Unsigned 32-bit integer

By right clicking on the Stateflow object that uses your custom code, you can access your custom code function. After right clicking on the object, hover over Explore. Your custom code function appears, denoted by (C function). Clicking the C function allows you to access the custom code from MATLAB.

Accessing Enumerations in Custom Code

To include enumerations from your custom code in charts that use C as the action language:

  1. Define your enumerations in a header file.

  2. Open the Configuration Parameters dialog box.

  3. In the Simulation Target pane, under Advanced parameters, select Import custom code.

  4. In the Code information tab, include the header file that defines your enumerations.

Related Topics