Stateflow User's Guide

Examples


Use this example index to jump to code examples in the documentation.

Getting Started

Creating a Simulink Model with a Stateflow Block
Drawing States in Stateflow Diagrams
Adding a Trigger Event to the Stateflow Diagram
Setting Up Diagram Simulation
Using the Debug Tool During Simulation

Stateflow Diagram Objects

Stateflow Diagram Objects
States
Transitions
Default Transitions
Conditions
History Junction
Actions
Connective Junctions

Exploring a Real-World Stateflow Application

Control Logic of the "fuel rate controller" Model
Overview of the "fuel rate controller" Model
Simulating the "fuel rate controller" Model
Implicit Event Broadcasts

Stateflow Hierarchy

Stateflow Hierarchy of Objects
Representing State Hierarchy Example
Transition Hierarchy

Active and Inactive States

Exclusive (OR) State Decomposition
Parallel (AND) State Decomposition

Label Notation

Transition Label Example

Transition Connections

Transitions to and from Exclusive (OR) States
Transitions to and from Junctions
Transitions to and from Exclusive (OR) Superstates
Self-Loop Transitions
Transitions to and from Substates

Inner Transitions

Before Using an Inner Transition
After Using an Inner Transition to a Connective Junction
Using an Inner Transition to a History Junction
Processing One Event in an Exclusive (OR) State
Processing a Second Event in an Exclusive (OR) State
Processing a Third Event in an Exclusive (OR) State
Processing the First Event with an Inner Transition to a Connective Junction
Processing a Second Event with an Inner Transition to a Connective Junction
Inner Transition to a History Junction Example

Default Transitions

Default Transition to a Junction Example
Default Transition with a Label Example
Default Transition in Exclusive (OR) Decomposition Example
Default Transition to a Junction Example
Default Transition and a History Junction Example
Labeled Default Transitions Example

Graphical Functions

Graphical Functions

Boxes

Boxes

History Junctions

Use of History Junctions Example

Connective Junctions

Connective Junction with All Conditions Specified Example
Connective Junction with One Unconditional Transition Example
Connective Junction--Self-Loop Example
Connective Junction and For Loops Example
Flow Diagram Notation Example
Connective Junction from a Common Source to Multiple Destinations Example
Connective Junction Common Events Example
Label Format for Transition Segments Example
If-Then-Else Decision Construct Example
Self-Loop Transition Example
For Loop Construct Example
Flow Diagram Notation 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

Early Return Logic for Event Broadcasts

Early Return Logic for Event Broadcasts

Transitions to and from Exclusive (OR) States

Transitioning from State to State with Events Example
Transitioning from a Substate to a Substate with Events Example

Condition Actions

Condition Action 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

Event Actions

Event Actions in a Superstate Example

Parallel (AND) States

Event Broadcast State Action Example
Event Broadcast Transition Action with a Nested Event Broadcast Example
Event Broadcast Condition Action Example

Directed Event Broadcasting

Directed Event Broadcast Using send Example
Directed Event Broadcasting Using Qualified Event Names Example

Charts

Creating a Stateflow Chart

Self-Loop Transitions

Creating Self-Loop Transitions

Stateflow Diagram Editor Window

Stateflow Diagram Editor Window
Using the Colors & Fonts Dialog

Supertransition

What Is a Supertransition?
Drawing a Supertransition Out of a Subchart
Drawing a Supertransition Into a Subchart

Smart and Nonsmart Transitions

Nonsmart Transitions Anchor Connection Points
Nonsmart Transitions Distort Asymmetrically
Smart Transitions Slide Around Surfaces
Smart Transitions Slide and Maintain Shape
Smart Transitions Connect States to Junctions at 90 Degree Angles
Smart Transitions Snap to an Invisible Grid
Smart Transitions Bow Symmetrically

Graphical Function

Creating a Function
Calling Functions in Stateflow

Note Font and Color

TeX Instructions

Data and Events

Adding Events in the Model Explorer
Adding Data in the Model Explorer
Sharing Input and Output Data with Simulink
Array Notation
Using Data and Event Arguments in Actions
Event Broadcast State Action Example
Event Broadcast Transition Action Example
Directed Event Broadcasting Using send
Directed Event Broadcasting Using Qualified Event Names
Symbol Autocreation Wizard

Action Language

State Action Types

MATLAB Functions and Variables

Inferring Return Size for ml Expressions
ml Data Type
Which ml Should I Use?
ml Expressions
ml Function
ml Namespace Operator

Custom C Code Functions

Function Call Transition Action Example
Function Call State Action Example

Temporal Logic Operators

Temporal Logic Events
every Temporal Logic Operator
at Temporal Logic Operator
before Temporal Logic Operator
after Temporal Logic Operator
Rules for Using Temporal Logic Operators

Fixed-Point Data

Fixed-Point "Bang-Bang Control" Example
Relational Operations (>, <, >=, <=, ==, -=, !=, <>).
:= Multiplication Example
:= Division Example
Offline and Online Conversion Examples

Simulink Interfaces

Triggered Stateflow Block Example
Sampled Stateflow Block Example
Inherited Stateflow Block Example
Continuous Stateflow Block Example
Function Call Output Events Example
Function Call Semantics Example
Edge-Triggered Semantics Example
Exported Event Example
Imported Event Example
Exported Data Example
Imported Data Example

Parsing in Stateflow

Parsing Diagram Example

Debugging

Debugging Run-Time Errors Example
State Inconsistency Example
Conflicting Transition Example
Data Range Violation Example
Cyclic Behavior Example
Flow Cyclic Behavior Not Detected Example
Noncyclic Behavior Flagged as a Cyclic Example

Model Coverage

Summary Report Section
Chart as Subsystem Details Report Section
Chart as Superstate Details Report Section
State Details Report Section
Transition Details Report Section
MCDC Coverage
Condition Coverage
Superstate Containing Exclusive OR Substates Decision

Search and Replace

Searching with Regular Expression Tokens
Replacing with Case Preservation
Replacing with Tokens

Stateflow Finder

Representing Hierarchy

Stateflow API

Create a New Model and Chart
Getting and Setting the Properties of Objects
Finding Objects at Different Levels of Containment
Finding Objects
Creating Stateflow Objects
Displaying Enumerated Values for Properties
Displaying Property Subproperties
Displaying the Names of Methods
Displaying Properties
Using Function Notation with Methods
Using Dot Notation with Properties and Methods
Create New Objects in the Chart
Access the Chart Object
Creating a MATLAB Script of API Commands
Creating Default Transitions
Entering Multiline Labels
Using the Editor Object
Accessing the Editor Object
Copying Objects Individually
Copying by Grouping (Recommended)