Main Content

Reuse Charts in Models with Chart Libraries

In Simulink®, you can create your own block libraries as a way to reuse the functionality of blocks or subsystems in one or more models. Similarly, you can reuse a set of Stateflow® algorithms by encapsulating the functionality in a chart library.

As with other Simulink block libraries, you can specialize each instance of chart library blocks in your model to use different data types, sample times, and other properties. Library instances that inherit the same properties can reuse generated code.

For more information about Simulink block libraries, see Custom Libraries (Simulink).

Create Specialized Chart Libraries for Large-Scale Modeling

  1. Add Stateflow charts with polymorphic logic to a Simulink model.

    Polymorphic logic is logic that can process data with different properties, such as type, size, and complexity.

  2. Configure the charts to inherit the properties you want to specialize.

    For a list, see Customize Properties of Library Blocks.

  3. Optionally, customize your charts using masking.

  4. Simulate and debug your charts.

  5. In Simulink, create a library model. In the Simulation tab, select New > Library

  6. Copy or drag the charts into a library model.

Customize Properties of Library Blocks

You can customize instances of Stateflow library blocks by allowing them to inherit any of the following properties from Simulink.

PropertyInherits by Default?How to Specify Inheritance
TypeYesSet the data type property to Inherit: Same as Simulink.
SizeYesSet the data size property to -1.
ComplexityYesSet the data complexity property to Inherited.
Limit rangeNoSpecify minimum and maximum values as Simulink parameters. For example, if minimum value = aParam and maximum value = aParam + 3, different instances of a Stateflow library block can resolve to different aParam parameters defined in their parent mask subsystems.
Initial valueDepends on scope

For local data, temporary data, and outputs, specify initial values as Simulink parameters. Other data always inherits the initial value:

  • Parameters inherit the initial value from the associated parameter in the parent mask subsystem.

  • Inputs inherit the initial value from the Simulink input signal.

  • Data store memory inherits the initial value from the Simulink data store to which it is bound.

Sampling mode (input)YesStateflow chart input ports always inherit sampling mode.
Data type override mode for fixed-point dataYesDifferent library instances inherit different data type override modes from their ancestors in the model hierarchy.
Sample time (block)YesSet the block sample time property to -1.

Limitations of Library Charts

  1. Events parented by a library chart are invalid. The Stateflow parser flags such events as errors.

  2. To include a linked library chart within another library chart, the two library charts must be in separate libraries.

  3. To include a linked library chart within a Simulink subsystem, first save the library chart within a subsystem and place that library subsystem in the Simulink subsystem.