Differences Between MATLAB and C as Action Language Syntax

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.

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

Compare Functionality of Action Languages

This table lists the most significant differences in functionality between the two action languages.

FunctionalityMATLAB as the Action LanguageC as the Action Language

Vector and matrix indexing

One-based indexing delimited by parentheses and commas. For example, A(4,5). See Supported Operations for Vectors and Matrices.

Zero-based indexing delimited by square brackets. For example, A[3][4]. See Supported Operations for Vectors and Matrices.

C constructs:

  • Increment and decrement operations a++ and a--

  • Assignment operations a += b, a –= b, a *= b, and a /= b

  • Evaluation operations a != b and !a

  • Binary operations a %% b, a >> b, a << b, a & b, and a | b

  • Comment markers // and /* */

Auto-correction to MATLAB syntax. For example, a++ is corrected to a = a+1. See Auto Correction When Using MATLAB as the Action Language.

Supported. See Supported Operations for Chart Data.

Conditional and loop control statements in state actions

Supported. For example, you can use if, for, and while statements in state actions. See Loops and Conditional Statements.

Not supported. For conditional and loop patterns, use graphical functions instead. See Reuse Logic Patterns by Defining Graphical Functions.

Format of transition actions

Auto-correction encloses transition actions with braces {}. See Transition Actions.

Not required to enclose transition actions with braces {}. See Transition Actions.

Ordering of parallel states

Explicit ordering only. See Execution Order for Parallel States.

Explicit or implicit ordering. See Execution Order for Parallel States.

Integer data types

Signed and unsigned integers with 64, 32, 16, or 8 bits.

Parameters that use signed or unsigned integers with 64 bits are not supported.

Signed and unsigned integers with 64, 32, 16, or 8 bits.

64-bit integers are implemented as fixed-point numbers:

  • int64 is an alias type for fixdt(1,64,0).

  • uint64 is an alias type for fixdt(0,64,0).

Fixed-point constructs:

  • Special assignment operator :=

  • Context-sensitive constants such as 4.3C

Not supported.

Supported. See Override Fixed-Point Promotion in C Charts and Fixed-Point Context-Sensitive Constants.

Complex data

Use complex number notation a + bi or the complex operator. See Supported Operations for Complex Data.

Use the complex operator. Complex number notation is not supported. See Supported Operations for Complex Data.

Data type propagation

Follows MATLAB typing rules. For example, adding data of type double to data of type int32 results in data of type int32.

Follows C typing rules. For example, adding data of type double to data of type int32 results in data of type double.

Explicit type cast operations

Use one of these casting forms:

  • MATLAB type conversion function. For example, single(x).

  • cast function with a type keyword. For example, cast(x,'int8').

  • cast function with the 'like' keyword. For example, cast(x,'like',z).

The type operator is not supported. See Type Cast Operations.

Use one of these casting forms:

  • MATLAB type conversion function. For example, uint16(x).

  • cast function with the type operator. For example, cast(x,type(z)).

Type keywords for the cast function are not supported. See Type Cast Operations.

Scalar expansion

Not supported.

Supported. See Assign Values to All Elements of a Matrix.
String data

Not supported.

Supported. See Manage Textual Information by Using Strings.

Specification of data properties:

  • First index

  • Save final value to base workspace

  • Units

Not supported.

Supported. For more information, see:

Scope of data in graphical, truth table, and MATLAB functions

Constant, Parameter, Input, OutputLocal, Constant, Parameter, Input, Output, Temporary

Dot notation for specifying states, local data, message, and local events inside MATLAB functions

Supported. See Identify Data by Using Dot Notation.

Not supported.

Custom code functions and variables

Behavior depends on the Import Custom Code configuration parameter.

  • When Import Custom Code is on, both custom code functions and variables are supported in states and transitions (default).

  • When Import Custom Code is off, only custom code functions are supported. Use the coder.ceval (MATLAB Coder) function.

See Custom Code and Import custom code.

Custom code functions and variables are supported in states and transitions.

Row-major array layout in generated code

Not supported.

Supported. See Row-Major Array Layout.

Multidimensional array layout in generated code

Not supported.

Supported for local data. See Multidimensional Array Layout.

Structure parameters

Tunable and nontunable parameters are supported.

Only tunable parameters are supported.

Use of global fimath object

Supported.

Not supported.

See Also

Related Topics