Stateflow | ![]() ![]() |
ml Expressions
You can mix ml
namespace operator and ml
function expressions along with Stateflow data in larger expressions. The following example squares the sine
and cosine
of an angle in workspace variable X
and adds them:
The first operand uses the ml
namespace operator to call the sin
function. Its argument is ml.X
, since X
is in the MATLAB workspace. The second operand uses the ml
function. Because X
is in the workspace, it is included in the evalString
expression as X
. The squaring of each operand is performed with the MATLAB power function, which takes two arguments: the value to square, and the power value, 2.
Expressions using the ml
namespace operator and the ml
function can be used as arguments for ml
namespace operator and ml
function expressions. The following example nests ml
expressions at three different levels:
In composing your ml
expressions, follow the levels of precedence set out in Binary and Bitwise Operations. To repeat a warning note in that section, be sure to use parentheses around power expressions with the ^
operator when you use them in conjunction with other arithmetic operators.
Stateflow checks expressions for data size mismatches in your action language during parsing of your charts and during run-time. Because the return values for ml
expressions are not known till run-time, Stateflow must infer the size of their return values. See Inferring Return Size for ml Expressions.
![]() | ml Function | Which ml Should I Use? | ![]() |