MATLAB Examples

Call Extrinsic Functions in a Stateflow Chart

To use extrinsic functions that are not supported for code generation within a chart that uses MATLAB as the action language, you must use coder.extrinsic. When you declare a function with coder.extrinisic('function_name') Stateflow creates a call to the function during simulation. In a Stateflow chart, you only declare coder.extrinsic once. You cannot declare reserved keywords with coder.extrinsic (see Rules for Naming Stateflow Objects).

For charts that include atomic subcharts, you must separately declare functions that are not supported for code generation individually with coder.extrinsic within the atomic subchart.

To create a call for the extrinsic function heaviside, the following model uses coder.extrinsic.

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, using coder.extrinsic. State B and the graphical function block also use heaviside without coder.extrinsic.

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 heaviside of any input in.

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.