Stateflow^{®} charts in Simulink^{®} models have an action language property that defines the syntax that you
use to compute with complex data. The action language properties are:

MATLAB

^{®}as the action language.C as the action language.

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

In charts that use MATLAB as the action language, you can define complex data by using complex
number notation `a + bi`

, where `a`

and
`b`

are real numbers. For example, this statement assigns a
value of 3+4i to `x`

:

x = 3 + 4i;

Alternatively, you can define complex data by using the `complex`

operator:

complex(<real_part>,<imag_part>)

* <real_part>* and

`<imag_part>`

`x`

:x = complex(3,4);

Charts that use C as the action language do not support complex number notation
`a + bi`

. To define a complex number based on two real values,
use the `complex`

operator.

This table summarizes the interpretation of all binary operations on complex operands according to their order of precedence (1 = highest, 3 = lowest). Binary operations are left associative so that, in any expression, operators with the same precedence are evaluated from left to right.

Operation | Precedence | MATLAB as the Action Language | C as the Action Language |
---|---|---|---|

| 1 | Multiplication. | Multiplication. |

| 1 | Division. | Not supported. Use the |

| 2 | Addition. | Addition. |

| 2 | Subtraction. | Subtraction. |

| 3 | Comparison, equal to. | Comparison, equal to. |

| 3 | Comparison, not equal to. | Comparison, not equal to. |

| 3 | Not supported. Use the operation | Comparison, not equal to. |

| 3 | Not supported. Use the operation | Comparison, not equal to. |

This table summarizes the interpretation of all unary operations and actions on complex data. Unary operations:

Have higher precedence than the binary operators.

Are right associative so that, in any expression, they are evaluated from right to left.

Operation | MATLAB as the Action Language | C as the Action Language |
---|---|---|

| Negative. | Negative. |

| Not supported. Use the expression | Increment. Equivalent to |

| Not supported. Use the expression | Decrement. Equivalent to |

This table summarizes the interpretation of assignment operations in Stateflow charts.

Operation | MATLAB as the Action Language | C as the Action Language |
---|---|---|

| Simple assignment. | Simple assignment. |

| Not supported. Use the expression | Equivalent to |

| Not supported. Use the expression | Equivalent to |

| Not supported. Use the expression | Equivalent to |

To access the real and imaginary parts of a complex number, use the
`real`

and `imag`

operators.

`real`

OperatorThe `real`

operator returns the
value of the real part of a complex number:

real(<complex_expr>)

* <complex_expr>* is an expression that evaluates
to a complex number. For example, if

`frame(200)`

evaluates to
the complex number `8.23 + 4.56i`

, this expression returns a
value of `8.2300`

:real(frame(200))

`imag`

OperatorThe `imag`

operator returns the
value of the imaginary part of a complex number:

imag(<complex_expr>)

* <complex_expr>* is an expression that evaluates
to a complex number. For example, if

`frame(200)`

evaluates to
the complex number `8.23 + 4.56i`

, this expression returns a
value of `4.5600`

:imag(frame(200))