Main Content

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 aschartName.功能ionName, select theExport chart level functionschart property, as described inSpecify Properties for Stateflow Charts.

  • 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,lib1Chartandlib2Chart. 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,xandy, with initial values of0and1, respectively. When you simulate the model, the default transition in this chart calls the functionlib1_funcusing these values as arguments.

The functionlib1_funcis defined in the library chartlib1Chart. The function reads its input arguments and passes them to the functionlib2_func.

The functionlib2_funcis defined in the library chartlib2Chart. The function reads its input arguments and passes them to the functionmain_func.

The functionmain_funcis 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 ofxincreasing 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.

Related Topics