This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Create and Edit Simulink Based States

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.

Create a Simulink Based State

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.

Create an Empty Simulink Based State

  1. Add a Stateflow chart block to a Simulink model. To open the Stateflow editor, double-click the block.

  2. On the object palette, click the Simulink based state drawing tool . Move your cursor onto your chart.

  3. To place the new Simulink based state, click the Stateflow canvas. A shaded state appears.

  4. 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.

  5. 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.

Create a Simulink Based State from an Enabled Subsystem

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.

  1. Open the sf_clutch_enabled_subsystems model.

  2. From the model, copy the block Slipping to your Stateflow chart.

  3. 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 .

Create a Linked Simulink Based State

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.

  1. Open the library model.

  2. Copy and paste the library block Run_up to your Stateflow chart.

  3. To display a link in the bottom leftmost corner on a linked subsystem, select Display > Library Links > All.

  4. 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 .

Create Inports and Outports

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:

  1. Open your Simulink based state.

  2. Click the Simulink canvas, type in1, and press Enter. An undefined inport is created.

  3. The undefined symbol in1 appears in the Symbols window of your Stateflow chart. To resolve the undefined symbol, click the Resolve undefined symbols button .

  4. A chart inport named In1 is created.

Create an Additional Outport

In this example, you create an additional outport for the model sf_pole_vault:

  1. To open the model.

  2. Open the chart PoleVaulter and double-click Simulink based state Take_off.

  3. Click the Simulink based state canvas and type out1 and press Enter. An undefined outport is created. Rename the outport theta_out and connect it to the signal for theta.

  4. In the Symbols window of PoleVaulter, an undefined symbol for theta_out appears. To resolve the undefined symbol, click the Resolve undefined symbols button .

  5. Stateflow creates an output in the chart called theta_out that corresponds to the outport theta_out.

For more information about editing data, see Add and Modify Data, Events, and Messages.

Related Topics