| Contents | Index |
• Finite State Machine Concepts
What Is a Finite State Machine?
Finite State Machine Representations
• Stateflow Charts and Simulink Models
The Simulink Model and the Stateflow Machine
Overview of Defining Stateflow Block Interfaces to Simulink Models
Common Graphical and Nongraphical Constructs
References for Chart Semantics
Model of the Check-In Process for a Hotel
How the Chart Interacts with Simulink Blocks
Execution of an Inactive Chart
Execution of a Chart with Super Step Semantics
Execution of a Chart at Initialization
Order of Execution for a Set of Flow Graphs
Detection of Transition Shadowing
Explicit Ordering of Outgoing Transitions
Implicit Ordering of Outgoing Transitions
What Happens When You Switch Between Explicit and Implicit Ordering
Transition Testing Order in Multilevel State Hierarchy
Steps for Executing an Active State
Steps for Exiting an Active State
Explicit Ordering of Parallel States
Implicit Ordering of Parallel States
How a Chart Maintains Order of Parallel States
How a Chart Assigns Execution Priorities to Restored States
What Happens When You Switch Between Explicit and Implicit Ordering
Specify State Actions and Transition Conditions
Define Persistent Data to Store State Variables
Simplify State Actions and Transition Conditions with Function Calls
Check That Your System Representation Is Complete
Creating Substates and Superstates
Specifying Substate Decomposition
Specifying Activation Order for Parallel States
Outputting State Activity to a Simulink Model
Straight and Curved Transitions
Changing Transition Arrowhead Size
Creating Self-Loop Transitions
Changing Transition Properties
Keyboard Shortcuts for Stateflow Charts
Displaying the Context Menu for Objects
Specifying Colors and Fonts in a Chart
Differentiating Syntax Elements in the Stateflow Action Language
Selecting and Deselecting Graphical Objects
Cutting and Pasting Graphical Objects
• Modeling Logic Patterns and Iterative Loops Using Flow Graphs
How to Create Reusable Flow Graphs
Saving and Reusing Flow Graph Patterns
MAAB-Compliant Patterns from the Pattern Wizard
Try It: Creating and Reusing a Custom Pattern with the Pattern Wizard
• Building Mealy and Moore Charts
Semantics of Mealy and Moore Machines
Running a Demo of Mealy and Moore Machines
The Default State Machine Type
Advantages of Mealy and Moore Charts Over Classic Stateflow Charts
• Techniques for Streamlining Chart Design
Changing History Junction Size
Changing History Junction Properties
Example of Converting a State to a Subchart
Manipulating Subcharts as Objects
Drawing a Supertransition Into a Subchart
Drawing a Supertransition Out of a Subchart
Setting Smart Behavior in Transitions
Why Use a Graphical Function in a Stateflow Chart?
Where to Use a Graphical Function
Workflow for Defining a Graphical Function
Managing Large Graphical Functions
Calling Graphical Functions in Stateflow Action Language
Exporting Chart-Level Graphical Functions
Diagnostic for Detecting Unused Data
Adding Data Using the Stateflow Editor
Adding Data Using the Model Explorer
What Is the Data Properties Dialog Box?
When to Use the Data Properties Dialog Box
Opening the Data Properties Dialog Box
Properties You Can Set in the General Pane
Properties You Can Set in the Logging Pane
Properties You Can Set in the Description Pane
Entering Expressions and Parameters for Data Properties
Sharing Output Data with Simulink
Sharing Simulink Parameters with Charts
Initializing Data from the MATLAB Base Workspace
Saving Data to the MATLAB Workspace
How Stateflow Charts Work with Local and Global Data Stores
Accessing Data Store Memory from a Stateflow Chart
Diagnostics for Sharing Data Between Stateflow Charts and Simulink Blocks
Creating a Global Data Store Across Multiple Models
Best Practices for Using Data Stores in Stateflow Charts
Exporting Data to External Modules
Importing Data from External Modules
Inheriting Data Types from Simulink Objects
Deriving Data Types from Previously Defined Data
Strong Data Typing with Simulink I/O
Inheriting Input or Output Size from Simulink Signals
Guidelines for Sizing Data with Numeric Values
Guidelines for Sizing Data with MATLAB Expressions
Examples of Valid Data Size Expressions
Name Conflict Resolution for Variables in Size Expressions
Best Practices for Sizing Stateflow Data
Support for Handling Integer Overflow in Charts
Effect of Integer Promotion Rules on Saturation
Impact of Saturation on Debugger Checks
Resolution of Data Identifiers with Dot Notation
Best Practices for Using Dot Notation in Data Identifiers
Enabling Explicit Signal Resolution
Diagnostic for Detecting Unused Events
Adding Events Using the Stateflow Editor
Adding Events Using the Model Explorer
Accessing the Event Properties Dialog Box
Using Edge Triggers to Activate a Stateflow Chart
Using Function Calls to Activate a Stateflow Chart
Association of Input Events with Control Signals
Behavior When the Parent Is the Model Root
Behavior When the Chart Is Inside a Model Block
Using Edge Triggers to Activate a Simulink Block
Using Function Calls to Activate a Simulink Block
Association of Output Events with Output Ports
Accessing Simulink Subsystems Triggered By Output Events
• Using Actions in Stateflow Charts
Execution of Actions in States and Transitions
Order of Execution of Combined Actions
Rules for Combining State Actions
Pointer and Address Operations
Replacing Operators with Target Functions
Hexadecimal Notation Symbols, 0xFF
Single-Precision Floating-Point Number Symbol, F
Replacement of C Math Library Functions with Target-Specific Implementations
Calling Custom C Code Functions
How Charts Infer the Return Size for ml Expressions
Example of Directed Event Broadcasting Using send
Example of Directed Event Broadcasting Using Qualified Event Names
Rules for Using Temporal Logic Operators
Operators for Event-Based Temporal Logic
Examples of Event-Based Temporal Logic
Notations for Event-Based Temporal Logic
Operators for Absolute-Time Temporal Logic
Defining Time Delays with Temporal Logic
Examples of Absolute-Time Temporal Logic
Running a Model That Uses Absolute-Time Temporal Logic
Behavior of Absolute-Time Temporal Logic in Conditionally Executed Subsystems
How Sample Time Affects Chart Execution
Best Practices for Using Absolute-Time Temporal Logic
Running a Model That Demonstrates Change Detection
How Checking State Activity Works
State Resolution for Identically Named Substates
Best Practices for Checking State Activity
Binding a Function-Call Subsystem to a State
Example Model That Binds a Function-Call Subsystem to a State
• Making States Reusable with Atomic Subcharts
Comparison of Modeling Methods
Comparison of Simulation Methods
Comparison of Code Generation Methods
Access to Data, Graphical Functions, and Events
Access to Local Data with a Nonzero First Index
Use of Strong Data Typing with Simulink Inputs and Outputs
Converting an Atomic Subchart to a State or Subchart
Restrictions for Converting an Atomic Subchart to a State or Subchart
How to Map Variables in an Atomic Subchart
Mapping Input and Output Data for an Atomic Subchart
Mapping Data Store Memory for an Atomic Subchart
Mapping Parameter Data for an Atomic Subchart
Mapping Input Events for an Atomic Subchart
How to Generate Reusable Code for Unlinked Atomic Subcharts
How to Enable Reuse of Utility Functions
Example of Reusing a Timer Function Multiple Times
Editing a Model to Use Atomic Subcharts
Propagating a Change in the Library Chart
Editing a Model to Use Atomic Subcharts
Editing a Model to Use Atomic Subcharts
Converting a State to an Atomic Subchart
• Saving and Restoring Simulations with SimState
Division of a Long Simulation into Segments
Test of a Chart Response to Different Settings
Simulating the Specific Segment
Loading the SimState and Modifying Values
Modifying SimState Values for One Actuator Failure
Testing the SimState for One Failure
Modifying SimState Values for Two Actuator Failures
Testing the SimState for Two Failures
Rules for Modifying Data Values
Rules for Modifying State Activity
Restriction on Continuous-Time Charts
No Partial Loading of a SimState
Restriction on Copying SimState Values
• Using Vectors and Matrices in Stateflow Charts
When to Use Vectors and Matrices
• Using Variable-Size Data in Stateflow Charts
• Using Enumerated Data in Stateflow Charts
Tasks for Defining Enumerated Data in a Chart
Defining an Enumerated Data Type in a File
Adding Enumerated Data to a Chart
Nonprefixed Notation for Enumerated Values
Prefixed Notation for Enumerated Values
Viewing Values of Enumerated Data After Simulation
Benefits of Using Enumerated Types in This Model
How the UserRequest Chart Works
How the CdPlayerModeManager Chart Works
How the CdPlayerBehaviorModel Chart Works
• Modeling Continuous-Time Systems in Stateflow Charts
What Is Continuous-Time Modeling?
When To Use Stateflow Charts for Continuous-Time Modeling
• Using Fixed-Point Data in Stateflow Charts
How Stateflow Software Defines Fixed-Point Data
Rules for Specifying Fixed-Point Word Length
Fixed-Point Context-Sensitive Constants
Tips for Using Fixed-Point Data
Detecting Overflow for Fixed-Point Types
Sharing Fixed-Point Data with Simulink Models
Exploring the Fixed-Point "Bang-Bang Control" Model
Building the Fixed-Point Butterworth Filter
Defining the Model Callback Function
Adding Other Blocks to the Model
Setting Configuration Parameters for the Model
Promotion Rules for Fixed-Point Operations
• Using Complex Data in Stateflow Charts
• Defining Interfaces to Simulink Models and the MATLAB Workspace
Typical Tasks to Define Stateflow Block Interfaces
Where to Find More Information on Events and Data
Setting Properties for a Single Chart
Setting Properties for All Charts in the Model
Defining a Sampled Stateflow Block
Defining an Inherited Stateflow Block
Defining a Continuous Stateflow Block
Defining Function-Call Output Events
Defining Edge-Triggered Output Events
Properties You Can Specialize Across Instances of Library Blocks
Examining the MATLAB Workspace
• Working with Structures and Bus Signals in Stateflow Charts
What Is a Stateflow Structure?
What You Can Do with Structures
• Truth Table Functions for Decision-Making Logic
Stateflow Classic Truth Tables
Selecting a Language for Stateflow Truth Tables
Migration from Stateflow Classic to MATLAB Truth Tables
Methods for Adding Truth Tables to Simulink Models
Adding a Stateflow Block that Calls a Truth Table Function
Entering Truth Table Conditions
Entering Truth Table Decisions
Assigning Truth Table Actions to Decisions
Adding Initial and Final Actions
Debugging a Truth Table During Simulation
Example of an Underspecified Truth Table
How Stateflow Software Generates Graphical Functions for Truth Tables
How Stateflow Software Generates MATLAB Code for Truth Tables
Deleting Text, Rows, and Columns
Selecting and Deselecting Table Elements
• Using MATLAB Functions in Stateflow Charts
• Using Simulink Functions in Stateflow Charts
Advantages of Using Simulink Functions in a Stateflow Chart
Benefits of Using a Simulink Function to Access Simulink Blocks
Benefits of Using a Simulink Function to Schedule Execution of Multiple Controllers
Task 1: Add a Function to the Chart
Task 2: Define the Subsystem Elements of the Simulink Function
Task 3: Configure the Function Inputs
Controlling Subsystem Variables When the Simulink Function Is Disabled
Example of Binding a Simulink Function to a State
Editing a Model to Use a Simulink Function
Code Generation for Stateflow Charts and Truth Table Blocks
Software Requirements for Building Targets
Choosing the Right Procedure for Simulation
Integrating Custom C++ Code for Simulation
Integrating Custom C Code for Nonlibrary Charts for Simulation
Integrating Custom C Code for Library Charts for Simulation
Integrating Custom C Code for All Charts for Simulation
Choosing the Right Procedure for Embeddable Code Generation
Integrating Custom C++ Code for Code Generation
Integrating Custom C Code for Nonlibrary Charts for Code Generation
Integrating Custom C Code for Library Charts for Code Generation
Integrating Custom C Code for All Charts for Code Generation
Design Tips for Optimizing Generated Code
Simulation Parameters for Nonlibrary Models
Simulation Parameters for Library Models
Code Generation Parameters for Nonlibrary Models
Code Generation Parameters for Library Models
Example of Using Custom C Code to Define Global Constants, Variables, and Functions
Adding a Stateflow Custom Target to Your Model
Restrictions on Building a Custom Target
Folder Structure of Generated Files
Code Files for a Simulation Target
Code Files for an Embeddable Target
Code Files for a Custom Target
Basic Workflow for Using Traceability
Examples of Using Traceability
Format of Traceability Comments
• Debugging and Testing Stateflow Charts
Opening the Stateflow Debugger
Setting Breakpoints to Debug Charts
How to Enable Debugging for Charts
Options for Controlling the Debugger
Creating the Model and the Stateflow Chart
Identifying Stateflow Objects in Error Messages
Conflicting Transitions in a Chart
Data Range Violations in a Chart
Watching Stateflow Data in the MATLAB Command Window
Examples of Changing Data Values
Limitations on Changing Data Values
Setting Test Points for Stateflow States and Local Data with the Model Explorer
Using a Floating Scope to Monitor Data Values and State Activity
Workflow for Logging States and Local Data
Enabling Signal Logging and Choosing a Logging Format
Configuring States and Local Data for Logging
Logging Data in Library Charts
• Exploring and Modifying Charts
Viewing Stateflow Objects in the Model Explorer
Editing Chart Objects in the Model Explorer
Adding Data and Events in the Model Explorer
Adding Custom Targets in the Model Explorer
Renaming Objects in the Model Explorer
Setting Properties for Chart Objects in the Model Explorer
Moving and Copying Data, Events, and Targets in the Model Explorer
Label Format for a State-to-State Transition Example
Transitioning from State to State with Events Example
Transitioning from a Substate to a Substate with Events Example
Condition and Transition Actions Example
Condition Actions in For-Loop Construct Example
Condition Actions to Broadcast Events to Parallel (AND) States Example
Cyclic Behavior to Avoid with Condition Actions Example
Default Transition to a Junction Example
Default Transition and a History Junction Example
Labeled Default Transitions Example
Processing Events with an Inner Transition to a Connective Junction Example
Inner Transition to a History Junction Example
If-Then-Else Decision Construct Example
Transitions from a Common Source to Multiple Destinations Example
Transitions from Multiple Sources to a Common Destination Example
Transitions from a Source to a Destination Based on a Common Event Example
Backtracking Behavior in Flow Graphs Example
Event Broadcast Transition Action with a Nested Event Broadcast Example
Stateflow API Object Hierarchy
Getting a Handle on Stateflow API Objects
What Are API Object Properties and Methods?
Creating a New Model and Chart
Creating New Objects in the Chart
Using Dot Notation with Properties and Methods
Using Function Notation with Methods
Displaying the Names of Methods
Displaying Property Subproperties
Displaying Enumerated Values for Properties
Establishing the Parent (Container) of an Object
Finding Objects and Properties
Finding Objects at Different Levels of Containment
Retrieving Recently Selected Objects
Getting and Setting the Properties of Objects
Example of Moving a Subcharted State
Rules for Moving Objects Programmatically
Copying by Grouping (Recommended)
• Blocks
| On this page… |
|---|
What Is a Finite State Machine? Finite State Machine Representations |
A Stateflow® chart is an example of a finite state machine. A finite state machine is a representation of an event-driven (reactive) system. In an event-driven system, the system makes a transition from one state (mode) to another, if the condition defining the change is true.
For example, you can use a state machine to represent the automatic transmission of a car. The transmission has these operating states: park, reverse, neutral, drive, and low. As the driver shifts from one position to another, the system makes a transition from one state to another, for example, from park to reverse.
Traditionally, designers used truth tables to represent relationships among the inputs, outputs, and states of a finite state machine. The resulting table describes the logic necessary to control the behavior of the system under study. Another approach to designing event-driven systems is to model the behavior of the system by describing it in terms of transitions among states. The occurrence of events under certain conditions determine the state that is active. State-transition charts and bubble charts are graphical representations based on this approach.
A Stateflow chart uses a variant of the finite state machine notation established by Harel [1]. A chart is a graphical representation of a finite state machine, where states and transitions form the basic building blocks of the system. You can also represent stateless charts (flow graphs). You can include Stateflow charts as blocks in a Simulink® model. The collection of Stateflow blocks in a Simulink model is the Stateflow machine.
A Stateflow chart enables the representation of hierarchy, parallelism, and history. You can organize complex systems by defining a parent and offspring object structure [2]. For example, you can organize states within other higher-level states. A system with parallelism can have two or more orthogonal states active at the same time. You can specify the destination state of a transition based on historical information. These characteristics go beyond what state-transition charts and bubble charts provide.
Notation defines a set of objects and the rules that govern the relationships between those objects. Stateflow chart notation provides a way to communicate the design information in a Stateflow chart.
Stateflow chart notation consists of these elements:
A set of graphical objects
A set of nongraphical text-based objects
Defined relationships between those objects
See Stateflow Chart Notation, for detailed information on Stateflow chart notation.
Semantics describe how to interpret chart notation. A typical Stateflow chart contains actions associated with transitions and states. The semantics describe the sequence of these actions during chart execution.
For a description of default semantics, see Stateflow Chart Semantics.
![]() | Stateflow Chart Concepts | Stateflow Charts and Simulink Models | ![]() |

Learn how engineers use Stateflow to model state machines in their Simulink models.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |

