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.
In charts that use C as the action language, you can call built-in MATLAB functions and access MATLAB workspace variables by using the
ml namespace operator
ml function. For more information, see Access MATLAB Functions and Workspace Data in C Charts.
In charts that use MATLAB as the action language, you can call MATLAB functions supported for code generation directly. To call extrinsic
functions that are not supported for code generation, you must use the
coder.extrinsic (MATLAB Coder) function. When you declare a function with
Stateflow creates a call to the function during simulation. In a Stateflow chart, you
coder.extrinsic once. You cannot declare reserved
coder.extrinsic. For more information, see Rules for Naming Stateflow Objects.
For charts that include atomic subcharts, you must declare functions that are not
supported for code generation with
coder.extrinsic separately within
the atomic subchart.
To enable calls to the extrinsic function
, this model uses
heaviside (Symbolic Math Toolbox)
The chart contains two parallel states, A and B, and one graphical function block,
foo. State A declares the function
heaviside, which is not supported for code generation, by using
coder.extrinsic. State B and the graphical function block also use
The input for state A is
u1, a sine wave, and the input for state B is
u2, a cosine wave. The graphical function
out outputs the value of the
heaviside function for the input
You only need to declare
heaviside once in your chart using
coder.extrinsic. After this you can use the
heaviside function anywhere within your chart without
coder.extrinsic. When generating code the functions that you declare using
coder.extrinsic will have a call to the extrinsic function, and that function will not appear in the generated code.
To visualize the result of this chart, open the scope.