| Stateflow | ![]() |
ml Function
You can use the ml function to specify calls to MATLAB functions through a string expression in the action language. The format for the ml function call uses standard function notation as follows:
evalString is a string expression that is evaluated in the MATLAB workspace. It contains a MATLAB command (or a set of commands, each separated by a semicolon) to execute along with format specifiers (%g, %f, %d, etc.) that provide formatted substitution of the other arguments (arg1, arg2, etc.) into evalString.
The format specifiers used in ml functions are the same as those used in the C functions printf and sprintf. The ml function call is equivalent to calling the MATLAB eval function with the ml namespace operator if the arguments arg1,arg2,... are restricted to scalars or string literals in the following command:
Stateflow assumes scalar return values from ml namespace operator and ml function calls when they are used as arguments in this context. See Inferring Return Size for ml Expressions.
In the following examples, x is a MATLAB workspace variable, and d1 and d2 are Stateflow data:
ml function calls the sin function of MATLAB to evaluate the sine of x in the MATLAB workspace. The result is then assigned to Stateflow data variable a. Because x is a workspace variable, and sin(x) is evaluated in the MATLAB workspace, you enter it directly in the evalString argument ('sin(x)').
sin function of MATLAB evaluates the sine of d1 in the MATLAB workspace and assigns the result to Stateflow data variable a. Because d1 is Stateflow data, its value is inserted in the evalString argument ('sin(%f)') using the format expression %f. This means that if d1 = 1.5, the expression evaluated in the MATLAB workspace is sin(1.5).
'matfunc(%g, ''abcdefg'', x, %f)' is the evalString shown in the preceding format statement. Stateflow data d1 and d2 are inserted into that string with the format specifiers %g and %f, respectively. The string ''abcdefg'' is a string literal with two single pairs of quotation marks used to enclose it because it is part of the evaluation string, which is already enclosed in single quotation marks.
sf_mat44. Stateflow data sf_mat44 must be defined in Stateflow as a 4-by-4 array before simulation. If its size is different, a size mismatch error is generated during run-time.
| ml Namespace Operator | ml Expressions | ![]() |