Operations for Complex Data in Stateflow
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.
Notation for Complex Data
In charts that use MATLAB as the action language, you can define complex data by using complex
number notation or by using the complex operator.
To use complex number notation, type 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. The
complex operator takes two arguments:
complex(<real_part>,<imag_part>)
The <real_part> and
<imag_part> argumentsspecify the real and
imaginary parts of the complex number. Both arguments must be real values or
expressions that evaluate to real values. This statement assigns a value of 3+4i to 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.
Binary Operations
Binary operations are left associative, meaning operators with the same precedence are evaluated from left to right. This table lists binary operations in order of precedence (1 = highest, 3 = lowest):
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. |
Unary Operations and Actions
Unary operations have higher precedence than binary operators and are right associative, meaning 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 |
Assignment Operations
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 |
Access Real and Imaginary Parts of a Complex Number
To access the real and imaginary parts of a complex number, use the real and imag operators.
real Operator
The 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 Operator
The 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))