Examples


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

Getting Started

Create a Simulink Model
Define Input Events
Create a Stateflow Diagram
Define the Stateflow Interface
Run a Simulation
Where Stateflow Generates Code for Simulation
Parse the Stateflow Diagram
Define Simulink Parameters
Save the Model
Debug the Model During Simulation

Stateflow Diagram Objects

Graphical Objects Example Diagram
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
Representing Transition Hierarchy Example

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

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

Graphical Functions

Graphical Functions

Boxes

Boxes

Action Language

Action Language Categories Example
Typecast Operations
Types of Action Language

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

Stateflow Diagram Editor Window

Stateflow Diagram Editor Window
Drawing Objects
Using the Colors & Fonts Dialog

Self-Loop Transitions

Creating Self-Loop Transitions

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

Calling Graphical Functions
Creating a Graphical Function

Note Font and Color

TeX Instructions

Supertransition

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

Data and Events

Using the Explorer to Define Events
Defining Data Arrays
Using the Explorer to Add Data
Defining Input Data
Defining Output Data
Array Notation
Data and Event Arguments
Event Broadcast State Action Example
Event Broadcast Transition Action Example
Directed Event Broadcast Using send Example
Directed Event Broadcast Using Qualified Event Names Example
Symbol Autocreation Wizard

Fixed-Point Data

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

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

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

Explorer

Transferring Properties Between Objects

Search and Replace

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

Stateflow Finder

Representing Hierarchy

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
MCDC Coverage
Condition Coverage
Superstate Containing Exclusive OR Substates Decision
Transition Report Section
State Report Section
Chart as Superstate Report Section
Chart as Subsystem Report Section

Stateflow API

Create a New Model and Chart
Create New Objects in the Chart
Access the Chart Object
Copying Objects Individually
Copying by Grouping (Recommended)
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 the Names of Properties
Using Function Notation with Methods
Using Dot Notation with Properties and Methods
Creating a MATLAB Script of API Commands
Creating Default Transitions
Entering Multiline Labels
Using the Editor Object
Accessing the Editor Object