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.
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.
Configure the charts to inherit the properties you want to specialize.
For a list, see Customize Properties of Library Blocks.
Optionally, customize your charts using masking.
Simulate and debug your charts.
In Simulink, create a library model. In the Simulation tab, select New > Library
Copy or drag the charts into a library model.
For an example using MATLAB Function blocks, see Create Custom Block Libraries.
You can customize instances of Stateflow library blocks by allowing them to inherit any of the following properties from Simulink.
|Property||Inherits by Default?||How to Specify Inheritance|
|Type||Yes||Set the data type property to Inherit: Same as Simulink.|
|Size||Yes||Set the data size property to -1.|
|Complexity||Yes||Set the data complexity property to Inherited.|
|Limit range||No||Specify minimum and maximum values as Simulink parameters. For example, if minimum value =
|Initial value||Depends on scope|
For local data, temporary data, and outputs, specify initial values as Simulink parameters. Other data always inherits the initial value:
|Sampling mode (input)||Yes||Stateflow chart input ports always inherit sampling mode.|
|Data type override mode for fixed-point data||Yes||Different library instances inherit different data type override modes from their ancestors in the model hierarchy.|
|Sample time (block)||Yes||Set the block sample time property to -1.|
Events parented by a library Stateflow machine are invalid. The parser flags such events as errors.
To include a linked library chart within another library chart, the two library charts must be in separate libraries.
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.