This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Modify the Action Language for a Chart

Icons for Action Language Syntax

Charts have an action language property that defines the syntax for state and transition actions. MATLAB® is the default action language syntax for new Stateflow® charts. These charts have a MATLAB icon in the lower-left corner.

Charts can also use C as the action language syntax. These charts have a C icon in the lower-left corner.

You can change the action language of a chart in the Action Language box of the Chart properties dialog box.

For more information, see Differences Between MATLAB and C as Action Language Syntax.

Change the Default Action Language

To change the default action language of new charts, use these commands.

sfpref('ActionLanguage','MATLAB')All new charts created have MATLAB as the action language, unless otherwise specified in sfnew.
sfpref('ActionLanguage','C')All new charts created have C as the action language, unless otherwise specified in sfnew.

For more information, see sfnew.

C to MATLAB Syntax Conversion

For nonempty charts, after you change the action language property from C to MATLAB, a notification appears at the top of the chart. The notification provides the option to convert some of the C syntax to MATLAB syntax. In the notification, click the link to have Stateflow convert syntax in the chart. C syntax constructs that are converted include:

  • Zero-based indexing

  • Binary and bit-wise operations

  • C style comments

  • Explicit casting for constant assignments

If the chart contains C constructs that cannot be converted to MATLAB, Stateflow shows a message in a dialog box. Click on the warnings link to display the warnings in the Diagnostic Viewer. Choose whether or not to continue with the conversion of supported syntax. C constructs not converted to MATLAB include:

  • Explicit type casts with cast and type

  • Operators such as &, * and :=

  • Custom data

  • Access to workspace variables using ml operator

  • Functions not supported in code generation

  • Hexadecimal and single precision notation

  • Context-sensitive constants

Rules for Using MATLAB as the Action Language

 Use unique names for data in a chart

 Use unique names for functions in a chart

 Include a type prefix for identifiers of enumerated values

 Use the MATLAB format for comments

 Use one-based indexing for vectors and matrices

 Use parentheses instead of brackets to index into vectors and matrices

 Do not use control flow logic in condition actions and transition actions

 Do not use transition actions in graphical functions

 Enclose transition actions with braces

 Do not declare global or persistent variables in state actions

 To generate code from your model, use MATLAB language features supported for code generation

 Assign an initial value to local and output data

Was this topic helpful?