| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Stateflow |
| Contents | Index |
| Learn more about Stateflow |
| On this page… |
|---|
What Is Continuous-Time Modeling? |
Continuous-time modeling allows you to simulate hybrid systems that use mode logic — that is, systems that respond to both continuous and discrete mode changes. A simple example of this type of hybrid system is a bouncing ball. The ball moves continuously through the air until it hits the ground, at which point a mode change — or discontinuity — occurs. As a result, the ball changes direction and velocity due to a sudden loss of energy. A later exercise shows you how to model a bouncing ball in continuous-time using a Stateflow chart (see Modeling a Bouncing Ball in Continuous-Time).
When you configure Stateflow charts for continuous-time simulation, they interact with the Simulink solver in the same way as other continuous blocks, as follows:
Maintain mode in minor time steps.
Stateflow charts do not update mode in minor time steps. This behavior ensures that outputs computed in a minor time step are based on the state of the chart during the last major time step.
Compute the state of the chart at each time step and expose the state derivative to the Simulink solver.
You can define local continuous variables to hold state information. Stateflow charts automatically provide programmatic access to the derivatives of state variables. Continuous solvers in Simulink models use this data to compute the chart's continuous states at the current time step, based on values from the previous time steps and the state derivatives.
Note For more information on how solvers work, see Solvers in the Simulink User's Guide. |
Can register zero crossings on state transitions.
Stateflow charts can register a zero-crossings function with a Simulink model to help determine when a state transition occurs. When the Simulink solver detects a change of mode, it searches forward from the previous major time step to detect when the zero crossing — or state transition — occurred.
Note For more information about how a Simulink model uses zero-crossing detection to simulate discontinuities in continuous states, see Zero-Crossing Detection in the Simulink User's Guide. |
Use Stateflow charts for modeling hybrid systems with modal behavior — that is, systems that transition from one mode to another in response to physical events and conditions, where each mode is governed by continuous-time dynamics.
In Stateflow charts, you can represent mode logic succinctly and intuitively as a series of states, transitions, and flow graphs. You can also easily represent state information as continuous local variables with automatic access to time derivatives, as described in About Continuous-Time Variables.
If your continuous or hybrid system does not contain mode logic, consider using a Simulink model (see Modeling a Continuous System in the Simulink User's Guide).
You can run the following continuous-time models with zero-crossing detection.
| Model | Description |
|---|---|
Modeling a Rectifier with Zero Crossings To open, click rectifier model | Rectifier takes a single (scalar) input and converts it to its absolute value. Illustrates how Stateflow charts register zero-crossing variables with Simulink models for accurate detection of mode changes. |
Modeling a Bouncing Ball To open, click bouncing ball model | Demonstrates how to model the dynamics of a bouncing ball by defining continuous-time state variables and their derivatives in Stateflow charts. To try it yourself, see Modeling a Bouncing Ball in Continuous-Time. |
Modeling Newton's Cradle To open, click Newton's Cradle model | Demonstrates how to model elastic collisions between balls in Newton's Cradle, a device that demonstrates conservation of momentum and energy. Uses vector assignment to continuous-time state variables. |
Modeling a Clutch To open, click clutch model | Implements the Simulink clutch demo model purely in a Stateflow chart. Represents the modal nature of the clutch using two states, Locked and Slipping. |
Modeling the Opening Shot in Pool To open, click pool model | Demonstrates how to model continuous systems that have a large number of discontinuous events, which rapidly (and unpredictably) change the dynamics. |
To run these continuous-time models:
At the MATLAB prompt, type:
demo simulink stateflow
In the Help browser, go to the section titled Zero Crossings and Derivatives in Stateflow.
Select the model of interest and follow the instructions.
![]() | Modeling Continuous-Time Systems in Stateflow Charts | Workflow for Creating Continuous-Time Charts | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |