ExportStateflowFunctions for Reuse
You can extend the scope of the chart-level functions in your Stateflow®chart to other blocks in the Simulink®model by exporting the functions. You can export:
Graphical functions
MATLAB®功能ions
Simulink functions
Truth tables
When you export chart-level functions, you can call them in other Stateflow charts andSimulink Callerblocks.
To export chart-level functions that you can call by using qualified notation such as
, select theExport chart level functionschart property, as described inSpecify Properties for Stateflow Charts.chartName
.功能ionName
To export chart-level functions that you can call without using qualified notation, selectExport chart level functions, and then selectTreat exported functions as globally visible. You cannot export functions with the same name.
For more information, seeCall a Simulink Function from a Model(Simulink).
Share Functions Across Stateflow Charts
This example shows how to call exported functions from other charts in your Simulink model. This model contains a main Stateflow chart,mainChart
, and two auxiliary library charts,lib1Chart
andlib2Chart
. Each chart contains a chart-level graphical function and has both theExport chart level functionsandTreat exported functions as globally visiblechart properties enabled.
The main chart contains two data objects,x
andy
, with initial values of0
and1
, respectively. When you simulate the model, the default transition in this chart calls the functionlib1_func
using these values as arguments.
The functionlib1_func
is defined in the library chartlib1Chart
. The function reads its input arguments and passes them to the functionlib2_func
.
The functionlib2_func
is defined in the library chartlib2Chart
. The function reads its input arguments and passes them to the functionmain_func
.
The functionmain_func
is defined in the main chart. The function adds its input arguments and returns the result. The main chart stores this result as the output datax
. The sequence of function calls repeats in each time step of the simulation. The Scope block shows the value ofx
increasing during the simulation.
Guidelines for Exporting Chart-Level Functions
Do Not Export Chart-Level Functions That Contain Unsupported Inputs or Outputs
You cannot export a chart-level function when inputs or outputs have any of the following properties:
定点数据类型与单词长度大的那n 32 bits
Variable size
Do Not Export Functions Across Model Reference Boundaries
You cannot export functions from a referenced model and call the functions from a parent model.
Combine Output and Update Functions When Generating Code
If you generate code for a model that uses exported chart-level functions, enable the model configuration parameterSingle output/update function(Simulink Coder)to ensure consistent behavior between simulation and code generation.