| Contents | Index |
• Modeling Logic Patterns and Iterative Loops Using Flow Graphs
• Building Mealy and Moore Charts
• Techniques for Streamlining Chart Design
• Using Actions in Stateflow Charts
• Making States Reusable with Atomic Subcharts
• Saving and Restoring Simulations with SimState
• Using Vectors and Matrices in Stateflow Charts
• Using Variable-Size Data in Stateflow Charts
• Using Enumerated Data in Stateflow Charts
• Modeling Continuous-Time Systems in Stateflow Charts
• About Continuous-Time Modeling
Workflow for Creating Continuous-Time Charts
Configuring a Stateflow Chart to Update in Continuous Time
When to Enable Zero-Crossing Detection
• Defining Continuous-Time Variables
• Modeling a Bouncing Ball in Continuous Time
• Design Considerations for Continuous-Time Modeling in Stateflow Charts
• 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
Keep Charts Closed During Simulation
Keep Scope Blocks Closed During Simulation
Use Library Charts in Your Model
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
Using the Symbol Wizard to Define Chart Symbols
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… |
|---|
To maintain the integrity — or smoothness — of the results in continuous-time modeling, you must constrain your charts to a restricted subset of Stateflow chart semantics. By restricting the semantics, the inputs do not depend on unpredictable factors — or side effects — such as:
Simulink solver's guess for number of minor intervals in a major time step
Number of iterations required to stabilize the integration loop or zero crossings loop
By minimizing side effects, a Stateflow chart can maintain its state at minor time steps and, therefore, update state only during major time steps when mode changes occur. Using this heuristic, a Stateflow chart can always compute outputs based on a constant state for continuous time.
A Stateflow chart generates informative errors to help you correct semantic violations.
Here are the rules for modeling continuous-time Stateflow charts:
Update local data only in transition, entry,
and exit actions
To maintain precision in continuous-time simulation, you should update local data (continuous or discrete) only during physical events at major time steps.
In Stateflow charts, physical events cause state transitions. Therefore, write to local data only in actions that execute during transitions, as follows:
State exit actions, which execute before leaving the state at the beginning of the transition
Transition actions, which execute during the transition
State entry actions, which execute after entering the new state at the end of the transition
Condition actions on a transition, but only if the transition directly reaches a state
Consider the following chart.

In this example, the action {n++} executes even when conditions c2 and c3 are false. In this case, n gets updated in a minor time step because there is no state transition.
Do not write to local continuous data in during actions because these actions execute in minor time steps.
Do not call Simulink functions in state during actions
or transition conditions
This rule applies to continuous-time charts because you cannot call functions during minor time steps. You can call Simulink functions in state entry or exit actions and transition actions. However, if you try to call Simulink functions in state during actions or transition conditions, an error message appears when you simulate your model.
For more information, see Using Simulink Functions in Stateflow Charts.
Compute derivatives only in during actions
A Simulink model reads continuous-time derivatives during minor time steps. The only part of a Stateflow chart that executes during minor time steps is the during action. Therefore, you should compute derivatives in during actions to give your Simulink model the most current calculation.
Do not read outputs and derivatives in state during actions
or transition conditions
This restriction provides smooth outputs in a major time step by preventing a chart from using values that might no longer be valid in the current minor time step. Instead, a chart computes outputs from local discrete data, local continuous data, and chart inputs.
Use discrete variables to govern conditions in during actions
This restriction prevents mode changes from occurring between major time steps. When placed in during actions, conditions that affect control flow should be governed by discrete variables because they do not change between major time steps.
Do not use input events in continuous-time charts
The presence of input events makes a chart behave like a triggered subsystem and therefore unable to simulate in continuous time. For example, the following model generates an error if the chart uses a continuous update method.

To model the equivalent of an input event, pass the input signal through a Hit Crossing block as an input to the continuous chart, as in this example.

When a mode change occurs during continuous-time simulation, the entry action of the destination state indicates to the Simulink model that a state transition occurred. If inner transitions are taken, the entry action is never executed.
Do not use event-based temporal logic. Use only absolute-time temporal logic for continuous-time simulation. See Operators for Absolute-Time Temporal Logic for details.
Event-based temporal logic has no meaning because there is no concept of a tick during a continuous-time simulation.
The chart must have at least one substate
In continuous-time simulation, the during action of a state updates the outputs. A chart with no state produces no output. To simulate the behavior of a stateless chart in continuous time, create a single state which calls a graphical function in its during action.
Do not use change detection operators in continuous charts
To implement change detection, Stateflow software buffers variables in a way that affects the behavior of charts between a minor time step and the next major time step.
Do not modify any SimState values for continuous-time charts
If you load the SimState for a continuous-time chart, you cannot modify the activity of states or any values of chart local or output data. Modifying the SimState of a continuous-time chart is not supported. For more information, see Rules for Using the SimState of a Chart.
![]() | Modeling a Bouncing Ball in Continuous Time | Using Fixed-Point Data in Stateflow Charts | ![]() |

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 |

