Getting Started
What Is Stateflow?
How Stateflow Works
Stateflow Works with Simulink
Stateflow Represents Control Modes with States
Stateflow Changes Active States with Transitions
Stateflow Reacts to Events
Stateflow Chooses Destinations with Junctions
Stateflow Uses Data Variables
Watching Stateflow Execute During Simulation
Generating C Code for Targets
Simulation Targets
Real-Time Workshop Targets
Custom Targets
Ways That You Can Use Stateflow
Before You Get Started
Required User Knowledge Level
Required and Optional Software
Stateflow Installation
Setting Up Your Own Target Compiler
Using Stateflow on a Laptop Computer
Controlling with States and Transitions
Building an On-Off Control Model
Creating a Simulink Model with a Stateflow Block
Saving a Simulink Model
Opening the Diagram for a Stateflow Block
Drawing States in Stateflow Diagrams
Drawing Transitions in a Stateflow Diagram
Adding a Trigger Event to the Stateflow Diagram
Sending a Trigger Event to the Stateflow Chart
Simulating a Stateflow Diagram
Setting Up Diagram Simulation
Simulating a Stateflow Diagram
Using the Debug Tool During Simulation
Guarding Transitions with Event Triggers
Adding Event Triggers to Transitions
Adding Multiple Trigger Events to a Stateflow Chart
Sending Multiple Trigger Events to a Stateflow Chart
Modifying Output Data with Actions
Adding State Entry Actions
Adding Output Data to the Stateflow Chart
Sending Stateflow Output Data to Simulink
Simulating Event Triggers and Modified Output Data
Controlling with Junctions
Adding a Sensor to the Model
Adding a Sensor Event
Adding Sensor Data
Adding a Junction for Flow Control
Deleting, Copying, and Renaming Stateflow Objects
Adding and Connecting Junctions
Entering Transition Conditions
Adding a Graphical Function for Convenience
Adding a Graphical Function
Calling a Graphical Function
Simulating with a Sensor Event, Junction, and Function
Simulating Junction Behavior
Introducing Stateflow Semantics
Using Junctions in Flow Diagrams
Controlling with Superstates
Adding Superstates to Simplify Control
Adding a Superstate
Simulating the Superstate
Adding a History Junction to Save State
Adding a History Junction to a Superstate
Simulating with a History Junction
Creating Subcharts to Add More Substates
Converting a State to a Subchart
Simulating a Subchart
Controlling Objects with Parallel Superstates
Creating Exclusive States
Creating Parallel States
Simulating Parallel States
Stateflow in Simulink
Controlling a Physical Plant
The Bang-Bang Boiler Demo
Where to Go from Here
Examples
Using Stateflow
Stateflow Concepts
Finite State Machine Concepts
What Is a Finite State Machine?
Finite State Machine Representations
Stateflow Representations
Notation
Semantics
References
Stateflow and Simulink
The Simulink Model and the Stateflow Machine
Stateflow Data Dictionary of Objects
Defining Stateflow Interfaces to Simulink
Stateflow Diagram Objects
States
Transitions
Default Transitions
Events
Data
Conditions
History Junction
Actions
Connective Junctions
Stateflow Hierarchy of Objects
Exploring a Real-World Stateflow Application
Overview of the "fuel rate controller" Model
Control Logic of the "fuel rate controller" Model
Simulating the "fuel rate controller" Model
Stateflow Notation
Overview of Stateflow Objects
Graphical Objects
Nongraphical Objects
The Stateflow Data Dictionary of Objects
States
What Is a State?
State Hierarchy
State Decomposition
State Labels
Transitions
What Is a Transition?
Transition Hierarchy
Transition Label Notation
Valid Transitions
Transition Connections
Transitions to and from Exclusive (OR) States
Transitions to and from Junctions
Transitions to and from Exclusive (OR) Superstates
Transitions to and from Substates
Self-Loop Transitions
Inner Transitions
Default Transitions
What Is a Default Transition?
Drawing Default Transitions
Labeling Default Transitions
Default Transition Examples
Connective Junctions
What Is a Connective Junction?
Flow Diagram Notation with Connective Junctions
History Junctions
What Is a History Junction?
History Junctions and Inner Transitions
Boxes
Graphical Functions
Stateflow Semantics
Executing an Event
Sources for Stateflow Events
Processing Events
Executing a Chart
Executing an Inactive Chart
Executing an Active Chart
Executing a Transition
Transition Flow Graph Types
Executing a Set of Flow Graphs
Transition Testing Order
Implicit Order Mode
Explicit Order Mode
Entering, Executing, and Exiting a State
Entering a State
Executing an Active State
Exiting an Active State
State Execution Example
Early Return Logic for Event Broadcasts
Semantic Examples
Transitions to and from Exclusive (OR) States Examples
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 Action Examples
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
Default Transition Examples
Default Transition in Exclusive (OR) Decomposition Example
Default Transition to a Junction Example
Default Transition and a History Junction Example
Labeled Default Transitions Example
Inner Transition Examples
Processing Events with an Inner Transition in an Exclusive (OR) State Example
Processing Events with an Inner Transition to a Connective Junction Example
Inner Transition to a History Junction Example
Connective Junction Examples
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
Event Actions in a Superstate Example
Parallel (AND) State Examples
Event Broadcast State Action Example
Event Broadcast Transition Action with a Nested Event Broadcast Example
Event Broadcast Condition Action Example
Directed Event Broadcasting Examples
Directed Event Broadcast Using send Example
Directed Event Broadcasting Using Qualified Event Names Example
Creating Stateflow Chart Diagrams
Creating a Stateflow Chart
Creating States in Stateflow Charts
Creating a State
Moving and Resizing States
Creating Substates and Superstates
Grouping States
Specifying Substate Decomposition
Specifying Activation Order for Parallel States
Changing State Properties
Labeling States
Outputting State Activity to Simulink
Creating Transitions in Stateflow Charts
Creating a Transition
Creating Straight Transitions
Labeling Transitions
Moving Transitions
Changing Transition Arrowhead Size
Creating Self-Loop Transitions
Creating Default Transitions
Changing Transition Properties
Creating Flowcharts with Connective Junctions
Creating a Connective Junction
Changing Connective Junction Size
Changing Junction Properties
Using the Stateflow Editor
Stateflow Diagram Editor Window
Displaying the Context Menu for Objects
Specifying Colors and Fonts
Selecting and Deselecting Objects
Cutting and Pasting Objects
Copying Objects
Editing Object Labels
Viewing Stateflow Objects in the Model Explorer
Zooming a Diagram
Undoing and Redoing Editor Operations
Keyboard Shortcuts for Stateflow Diagrams
Extending Stateflow Chart Diagrams
Using History Junctions to Extend Charts and States
Creating a History Junction
Changing History Junction Size
Changing History Junction Properties
Using Subcharts to Extend Charts
What Is a Subchart?
Creating a Subchart
Manipulating Subcharts as Objects
Opening a Subchart
Editing a Subchart
Navigating Subcharts
Using Supertransitions to Extend Transitions
What Is a Supertransition?
Drawing a Supertransition Into a Subchart
Drawing a Supertransition Out of a Subchart
Labeling Supertransitions
Extending Transitions with Smart Behavior
Setting Smart Behavior in Transitions
What Smart Transitions Do
What Nonsmart Transitions Do
Using Functions to Extend Actions
Creating a Function
Programming Functions
Defining Function Data
Calling Functions in Stateflow
Exporting Functions
Specifying Function Properties
Using Boxes to Extend Chart Diagrams
Creating a State
Changing a State to a Box
Using Boxes in Stateflow
Using Notes to Extend Chart Diagrams
Creating Notes
Editing Existing Notes
Changing Note Font and Color
Moving Notes
Deleting Notes
Reporting Chart Diagrams
Printing and Reporting on Stateflow Charts
Generating a Model Report in Stateflow
Printing the Current Stateflow Diagram
Printing a Stateflow Book
Defining Events and Data
Adding Events
Adding Events in the Stateflow Diagram Editor
Adding Events in the Model Explorer
Setting Event Properties in the Event Dialog
Sharing Events with Simulink
Defining Input Events
Associating Input Events with Control Signals
Defining Output Events
Associating an Output Event with an Output Port
Sharing Events with Stateflow External Code
Exporting Events to Stateflow External Code
Importing Events from Stateflow External Code
Defining Implicit Events
Referencing Implicit Events
Example of an Implicit Event
Adding Data
Adding Data to the Data Dictionary
Defining Temporary Data
Setting Data Properties in the Data Dialog
Setting General Data Properties
Setting Value Attribute Data Properties
Setting Description Data Properties
Sharing Stateflow Data with Simulink and MATLAB
Sharing Input and Output Data with Simulink
Resolving Signal Objects for Output Data
Bringing Simulink Parameters into Stateflow
Initializing Data from the MATLAB Base Workspace
Saving Data to the MATLAB Workspace
Sharing Data with Stateflow External Code
Exporting Data to External Stateflow Code
Importing Data from External Stateflow Code
Typing Stateflow Data
Selecting Stateflow Data Types
Inheriting Input and Output Data Type from Simulink
Typing Data by Using the Type of Other Data
Typing Data by Using an Alias
Sizing Stateflow Data
Inheriting Input and Output Data Size from Simulink
Sizing Data by Expression
Using Actions in Stateflow
Defining Action Types
State Action Types
Transition Action Types
Example of Action Type Execution
Using Operations in Actions
Binary and Bitwise Operations
Unary Operations
Unary Actions
Assignment Operations
Pointer and Address Operations
Type Cast Operations
Using Special Symbols in Actions
Comment Symbols
Hexadecimal Notation Symbols
Infinity Symbol, inf
Line Continuation Symbol, ...
Literal Code Symbol, $
MATLAB Display Symbol, ;
Single-Precision Floating-Point Number Symbol, F
Time Symbol, t
Calling C Functions in Actions
Calling C Library Functions
Calling the abs Function
Calling min and max Functions
Calling User-Written C Code Functions
Using MATLAB Functions and Data in Actions
ml Namespace Operator
ml Function
ml Expressions
Which ml Should I Use?
ml Data Type
Inferring Return Size for ml Expressions
Using Data and Event Arguments in Actions
Using Arrays in Actions
Array Notation
Arrays and Custom Code
Broadcasting Events in Actions
Event Broadcasting
Directed Event Broadcasting
Using Temporal Logic in Actions
Rules for Using Temporal Logic Operators
after Temporal Logic Operator
before Temporal Logic Operator
at Temporal Logic Operator
every Temporal Logic Operator
Conditional and Event Notation
Temporal Logic Events
Using Bind Actions to Control Function-Call Subsystems
Binding a Function-Call Subsystem
Simulating a Bound Function-Call Subsystem
Using Stateflow Logic with Binding
Avoiding Muxed Trigger Events with Binding
Using Fixed-Point Data in Stateflow
What Is Fixed-Point Data?
Fixed-Point Numbers
Fixed-Point Operations
Using Fixed-Point Data in Stateflow
How Stateflow Defines Fixed-Point Data
Specifying Fixed-Point Data in Stateflow
Fixed-Point Context-Sensitive Constants
Tips for Using Fixed-Point Data in Stateflow
Overflow Detection for Fixed-Point Types
Sharing Fixed-Point Data with Simulink
Fixed-Point "Bang-Bang Control" Example
Opening the Fixed-Point "Bang-Bang Control" Example
Exploring the Fixed-Point "Bang-Bang Control" Example
Operations with Fixed-Point Data
Supported Operations with Fixed-Point Operands
Promotion Rules for Fixed-Point Operations
Assignment (=, :=) Operations
Fixed-Point Conversion Operations
Autoscaling of Stateflow Fixed-Point
Defining Interfaces to Simulink and MATLAB
Overview of Stateflow Interfaces
Stateflow Interfaces
Typical Tasks to Define Stateflow Interfaces
Where to Find More Information on Events and Data
Specifying Chart Properties
Setting Properties for Individual Charts
Setting Properties for All Charts in the Model
Setting the Stateflow Block Update Method
Implementing Simulink Update Interfaces
Defining a Triggered Stateflow Block
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
Creating Chart Libraries
MATLAB Workspace Interfaces
Examining the MATLAB Workspace in MATLAB
Interfacing the MATLAB Workspace in Stateflow
Interface to External Sources
Exported Events
Imported Events
Exported Data
Imported Data
Truth Table Functions
What Is a Truth Table?
Building a Simulink Model with a Stateflow Truth Table
Creating a Simulink Model
Creating a Stateflow Truth Table
Calling a Truth Table in a Stateflow Action
Creating Truth Table Data in Stateflow and Simulink
Programming a Truth Table
Opening a Truth Table for Editing
Entering Truth Table Conditions
Entering Truth Table Decisions
Entering Truth Table Actions
Assigning Truth Table Actions to Decisions
Adding Initial and Final Actions
Debugging a Truth Table
Checking Truth Tables for Errors
Specifying a Breakpoint for the Call to a Truth Table
Debugging a Truth Table During Simulation
Options for Assigning Actions to Decisions in Truth Tables
Truth Table Editor Operations
Truth Table Editor Reference
Searching and Replacing in Truth Tables
Using Row and Column Tooltip Identifiers
Correcting Over- and Underspecified Truth Tables
Defining an Overspecified Truth Table
Defining an Underspecified Truth Table
Model Coverage for Truth Tables
How Stateflow Realizes Truth Tables
Viewing the Graphical Function for a Truth Table
How Stateflow Generates Graphical Functions for Truth Tables
Using Embedded MATLAB Functions
Introduction to Embedded MATLAB Functions
Building a Simulink Model with a Stateflow Embedded MATLAB Function
Programming a Stateflow Embedded MATLAB Function
Debugging a Stateflow Embedded MATLAB Function
Checking Embedded MATLAB Functions for Syntax Errors
Run-Time Debugging for Embedded MATLAB Functions
Model Coverage for an Embedded MATLAB Function
Types of Model Coverage in Embedded MATLAB Functions
Creating a Model with Embedded MATLAB Function Decisions
Understanding Embedded MATLAB Function Model Coverage
Building Targets
Overview of Stateflow Targets
What Is a Simulink RTW Target?
What Is a Stateflow Target?
How Do You Build a Target?
How Does Stateflow Build into Targets?
Adding a Stateflow Target
Configuring a Simulation Target for Stateflow
Configuring Real-Time Workshop for Stateflow
Configuring Stateflow Blocks in Nonlibrary Models for Real-Time Workshop
Configuring the Stateflow Blocks in Library Models for Real-Time Workshop
Configuring a Custom Target in Stateflow
Integrating Custom Code with Stateflow Targets
Specifying Custom Code Options for Stateflow Targets
Specifying Relative Paths for Custom Code
Including Custom C++ Code
Calling Graphical Functions from Custom Code
Starting the Build
Starting a Simulation Target Build
Starting an RTW Target Build
Parsing Stateflow Diagrams
Calling the Stateflow Parser
Parser Error Checking
Parsing Diagram Example
Resolving Event, Data, and Function Symbols
Error Messages
Parser Error Messages
Code Generation Error Messages
Compilation Error Messages
Generated Files
DLL Files
Code Files
Makefiles
Debugging and Testing
Debugging with the Debugging Window
Setting Breakpoints for Debugging
Setting Error Checking in the Debugging Window
Starting Simulation in the Debugging Window
Controlling Animation in the Debugging Window
Controlling the Execution Rate in the Debugging Window
Setting the Output Display Pane
Debugging Run-Time Errors Example
Create the Model and Stateflow Diagram
Debugging the Stateflow Diagram
Correcting the Run-Time Error
Debugging State Inconsistencies
Causes of State Inconsistency
Detecting State Inconsistency
State Inconsistency Example
Debugging Conflicting Transitions
Detecting Conflicting Transitions
Conflicting Transition Example
Debugging Data Range Violations
Detecting Data Range Violations
Data Range Violation Example
Debugging Cyclic Behavior
Cyclic Behavior Example
Flow Cyclic Behavior Not Detected Example
Noncyclic Behavior Flagged as a Cyclic Example
Watching Data Values with Debuggers
Watching Data in the Stateflow Debugger
Watching Stateflow Data in MATLAB
Monitoring Stateflow Test Points
Setting Test Points for Stateflow States and Local Data with Model Explorer
Logging Data Values and State Activity
Using a Floating Scope to Monitor Data Values and State Activity
Understanding Model Coverage for Stateflow Charts
Making Model Coverage Reports
Specifying Coverage Report Settings
Cyclomatic Complexity
Decision Coverage
Condition Coverage
MCDC Coverage
Coverage Reports for Stateflow Charts
Colored Stateflow Diagram Coverage Display
Exploring and Modifying Charts
Using the Model Explorer with Stateflow Objects
Viewing Stateflow Objects in the Model Explorer
Editing States or Charts in the Model Explorer
Adding Data and Events in the Model Explorer
Adding a Target in the Model Explorer
Renaming Objects in the Model Explorer
Setting Properties for Stateflow Objects in the Model Explorer
Moving and Copying Data, Events, and Targets in the Model Explorer
Changing the Port Order of Input and Output Data and Events
Deleting Data, Events, and Targets in the Model Explorer
Using the Stateflow Search & Replace Tool
Opening the Search & Replace Tool
Using Different Search Types
Specify the Search Scope
Using the Search Button and View Area
Specifying the Replacement Text
Using the Replace Buttons
Search and Replace Messages
Using the Stateflow Finder Tool
Opening Stateflow Finder
Using Stateflow Finder
Finder Display Area
API Guide and Reference
Using the Stateflow API
Overview of the Stateflow API
What Is the Stateflow API?
Stateflow API Object Hierarchy
Getting a Handle on Stateflow API Objects
Using API Object Properties and Methods
API References to Properties and Methods
Quick Start for the Stateflow API
Create a New Model and Chart
Access the Model Object
Access the Chart Object
Create New Objects in the Chart
Accessing the Properties and Methods of Objects
Naming Conventions for Properties and Methods
Using Dot Notation with Properties and Methods
Using Function Notation with Methods
Displaying Properties and Methods
Displaying Properties
Displaying the Names of Methods
Displaying Property Subproperties
Displaying Enumerated Values for Properties
Creating and Destroying API Objects
Creating Stateflow Objects
Establishing an Object's Parent (Container)
Destroying Stateflow Objects
Accessing Existing Stateflow Objects
Finding Objects
Finding Objects at Different Levels of Containment
Getting and Setting the Properties of Objects
Copying Objects
Accessing the Clipboard Object
copy Method Limitations
Copying by Grouping (Recommended)
Copying Objects Individually
Using the Editor Object
Accessing the Editor Object
Changing the Stateflow Display
Entering Multiline Labels
Creating Default Transitions
Making Supertransitions
Creating a MATLAB Script of API Commands
API Properties and Methods by Use
Reference Table Column Descriptions
Access Methods
Code Generation and Target Building
Code Generation and Build Methods
Code Generation Properties
Custom Code Properties
Display Control
Display Methods
Display Properties
Graphical Appearance
Color Properties
Drawing Properties
Font Properties
Position Properties
Text Properties
Creating and Deleting Objects
Containment
Data Definition Properties
Debugging Properties
Identifiers
Interface to Simulink
Machine (Model) Identifier Properties
Truth Table Construction Properties
Utilities
API Properties and Methods by Object
Reference Table Columns
Objectless Methods
Constructor Methods
Editor Properties
Editor Methods
Clipboard Methods
All Object Methods
Root Methods
Machine Properties
Machine Methods
Chart Properties
Chart Methods
State Properties
State Methods
Box Properties
Box Methods
Graphical Function Properties
Graphical Function Methods
Truth Table Properties
Truth Table Methods
Embedded MATLAB Function Properties
Embedded MATLAB Function Methods
Note Properties
Note Methods
Transition Properties
Transition Methods
Junction Properties
Junction Methods
Data Properties
Data Methods
Event Properties
Event Methods
Target Properties
Target Methods
API Methods -- Alphabetical List
build
classhandle
copy
defaultTransitions
delete
dialog
disp
find
generate
get
getCodeFlag
help
innerTransitions
make
methods
outerTransitions
outputData
parse
pasteTo
rebuildAll
regenerateAll
set
setCodeFlag
sfclipboard
sfexit
sfhelp
sfnew
sfprint
sfroot
sfsave
sfversion
sourcedTransitions
stateflow
Stateflow.Box
Stateflow.Data
Stateflow.EMFunction
Stateflow.Event
Stateflow.Function
Stateflow.Junction
Stateflow.Note
Stateflow.State
Stateflow.Target
Stateflow.Transition
Stateflow.TruthTable
struct
up
view
zoomIn and zoomOut
Stateflow
Semantic Rules Summary for Stateflow
Entering a Chart
Executing an Active Chart
Entering a State
Executing an Active State
Exiting an Active State
Executing a Set of Flow Graphs
Executing an Event Broadcast
Glossary
Printable Documentation (PDF)
Product Page (Web)