Main Content

Modify the Action Language for a Chart

Stateflow® charts in Simulink® models have an action language property that defines the syntax for state and transition actions. An icon in the lower-left corner of the chart canvas indicates the action language for the chart.

  • MATLAB® as the action language.

  • C as the action language.

Convert Charts Between Action Languages

To convert between action languages, change the Action language chart property. In the Chart properties dialog box, select the new action language. If your chart contains actions, Stateflow notifies you of the option to convert syntax patterns.

Change the Default Action Language

MATLAB is the default action language syntax for new Stateflow charts. To create a chart that uses C as the action language, enter:

sfnew -C

To change the default action language of new charts, use the sfpref function. For example, to set C as the action language for new charts, enter:

sfpref(ActionLanguage="C");

C to MATLAB Syntax Conversion

When you change a chart with existing actions from C action language to MATLAB action language, Stateflow displays a notification at the top of the chart. Click the conversion link in the notification to update supported syntax patterns.

Stateflow converts these C constructs to MATLAB syntax:

  • Array indexing: A[0][1] becomes A(1,2)

    Increment operations: a++ becomes a = a+1

    Assignment operations: a += b becomes a = a+b

    Remainder operation: a %% b becomes rem(a,b)

    Bit shift operations: a >> b becomes bitshift(a,-b)

    Bitwise operations: a ^ b becomes bitxor(a,b) (when Enable C-bit operations is selected)

    Comments: // and /* */ become %

You must manually update:

  • Explicit type casts with the cast and type operators.

  • Pointer operators such as & and *.

  • Special assignment operator :=.

  • Custom data declarations.

  • Workspace variable access using ml operator.

  • Functions not supported for code generation.

  • Hexadecimal notation and single precision literals.

  • Context-sensitive constants.

See Also

Topics