Skip to Main Content Skip to Search
Product Documentation

Basic Workflow for Building a State Chart

Identify System Attributes

Before you build the state chart, identify your system attributes by answering these questions:

  1. What are your interfaces?

    1. What are the event triggers to which your system reacts?

    2. What are the inputs to your system?

    3. What are the outputs from your system?

  2. Does your system have any operating modes?

    1. If the answer is yes, what are the operating modes?

    2. Between which modes can you transition? Are there any operating modes that run in parallel?

    If your system has no operating modes, the system is stateless. If your system has operating modes, the system is modal.

Select a State Machine Type

After identifying your system attributes, the first step is to create a new chart and select one of the following state machine types:

For more information about Classic charts, see Stateflow Chart Semantics. For more information about Mealy and Moore charts, see Building Mealy and Moore Charts.

Specify State Actions and Transition Conditions

After you create an empty chart, answer the following questions:

  1. For each state, what are the actions you want to perform?

  2. What are the rules for transitioning between your states? If your chart has no states, what are the rules for transitioning between branches of your flow logic?

Using your answers to those questions, specify state actions and transition conditions:

  1. Draw states to represent your operating modes, if any. See Working with States in Charts.

  2. Implement the state actions by adding state labels that use the appropriate syntax. See State Action Types.

  3. Draw transitions to represent the direction of flow logic, between states or between branches of your flow graph. See Working with Transitions in Charts.

  4. Implement the transition conditions by adding transition labels that use the appropriate syntax. See Transition Action Types.

Define Persistent Data to Store State Variables

After adding state actions and transition conditions to your chart, determine if the chart requires any local or persistent data to store state variables. If so, follow these steps:

  1. Add local data to the appropriate level of the chart hierarchy. See Adding Data.

  2. Specify the type, size, complexity, and other data properties. See Setting Data Properties in the Data Dialog Box.

Simplify State Actions and Transition Conditions with Function Calls

State actions and transition conditions can be complex enough that defining them in-line on the state or transition is not feasible. In this case, express the actions or conditions using one of the following types of Stateflow functions:

Use the function format that is most natural for the type of calculation in the state action or transition condition. For more information on the four types of functions, see:

If the four types of Stateflow functions do not work, you can write your own C or C++ code for integration with your state chart. For more information about custom code integration, see Building Targets.

Check That Your System Representation Is Complete

Does your Stateflow chart fully express the logical or event-driven components of your system?

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS