To model systems that switch between periodic or continuous time dynamics, use Simulink® based states. Simulink based states are supported only in Stateflow® charts in a Simulink model. For more information, see Simulink Subsystems as States.
You can create Simulink based state by using the drawing tool. To reuse systems from separate Simulink models, copy and paste enabled subsystems. To reuse subsystems in multiple Stateflow charts, copy and paste action subsystems that are saved in a library.
To create a Simulink based state, do one of the following:
Create an empty Simulink based state by using the Simulink based state drawing tool.
Create a Simulink based state from another model by copying an enabled subsystem or an action subsystem to your Stateflow chart.
Create a linked Simulink based state by copying an action subsystem from a library to your Stateflow chart.
Add a Stateflow chart block to a Simulink model. To open the Stateflow editor, double-click the block.
On the object palette, click the Simulink based state drawing tool . Move your cursor onto your chart.
To place the new Simulink based state, click the Stateflow canvas. A shaded state appears.
Enter the state label. In this example, the state models a pole
vaulter running along a flat surface, so the state label is
Run_up. Simulink based states are action subsystems, so an Action Port
appears with your new state.
Build your Simulink subsystem. This subsystem outputs the Cartesian coordinates of the pole vaulter. For more information about this model, see Access Block State Data.
To create a Simulink based state in your Stateflow chart, copy enabled subsystems from separate Simulink models. You can reuse components from Simulink models in a Stateflow chart without creating a brand new Simulink based state.
From the model, copy the block
Slipping to your
The inports and outports of your Simulink subsystem appear as undefined symbols in your Stateflow chart. To add corresponding input and output data to your Stateflow chart, click the Resolve undefined symbols button .
To create a linked Simulink based state in your Stateflow chart, copy an action subsystem from a library to Stateflow. When the library block is updated, the changes are reflected in all Stateflow charts containing the block.
Open the library model.
Copy and paste the library block
Run_up to your
To display a link in the bottom leftmost corner on a linked subsystem, select Display > Library Links > All.
The outports of this Simulink subsystem,
xy, appears as an
undefined symbol in your Stateflow chart. To add a corresponding output data to your
Stateflow chart, click the Resolve undefined
symbols button .
When using Simulink based states, inports and outports for your Simulink subsystem connect to input and output data at the Stateflow chart level. This connection allows the top-level Simulink model to read data from the subsystem contained within your Simulink based state.
When you create an empty Simulink based state, Stateflow creates inputs and outputs in your Simulink subsystem that correspond to inputs and outputs that exist in the parent Stateflow chart. However, if you add inports and outports to your Simulink based state after it is created, you must create corresponding input and output data for your Stateflow chart.
To create additional inports or outports for a Simulink based state:
Open your Simulink based state.
Click the Simulink canvas, type
in1, and press
Enter. An undefined inport is created.
The undefined symbol
in1 appears in the Symbols window
of your Stateflow chart. To resolve the undefined symbol, click the
Resolve undefined symbols button .
A chart inport named
In1 is created.
In this example, you create an additional outport for the model
To open the model.
Open the chart
PoleVaulter and double-click
Simulink based state
Click the Simulink based state canvas and type
press Enter. An undefined outport is created. Rename
theta_out and connect it to the signal
In the Symbols window of
PoleVaulter, an undefined
theta_out appears. To resolve the
undefined symbol, click the Resolve undefined
symbols button .
Stateflow creates an output in the chart called
theta_out that corresponds to the outport
For more information about editing data, see Add and Modify Data, Events, and Messages.