Stateflow

 

Stateflow

Model and simulate decision logic using state machines and flow charts

Video length is 2:06

Connect AI Agents to Stateflow

Bring domain-specific capabilities to your agentic AI workflow.

Design State Machines

With Stateflow, you can design state machines using drag and drop elements and simple logic statements. Stateflow Onramp and training are available to help you get started.

State chart with multiple states and MATLAB function blocks. The “exchange” state contains logic represented using a flow chart to determine whether it enters into one of two child states or exits the state.

Create Flow Charts

You can use flow charts to represent state logic. The Pattern Wizard lets you automatically generate flow charts for common logic patterns.

Model Logic with Tables

Stateflow has State Transition Tables and Truth Tables. State Transition Tables offer a tabular view for modeling logic, and Truth Tables implement combinatorial logic design in a tabular format.

Execute Stateflow Charts

When executing your state diagram, animations highlight active states and transitions. You can manually modify variables during execution to visualize their impact on the system.

On the left is a Stateflow chart for a manual gear shift. The simulation data for two of the chart’s states are captured in graphs on the right, with arrows identifying each state’s corresponding plot.

Monitor and Analyze Data

Simulation Data Inspector provides the ability to visualize simulation data. With this tool, you can monitor a system to gather valuable insights on its behavior.

Debug Logic in Stateflow

Stateflow debugging capabilities let you step through chart execution in detail. You can set breakpoints and step through different functions in your state diagrams to understand unexpected behavior.

A Temporal Logic Scheduler is implemented in a Simulink model. The block schedules the execution of three function-call subsystems, the third of which is outputting to a Scope block.

Stateflow Task Scheduling

Stateflow can invoke Simulink algorithms in a periodic or continuous manner to schedule the execution of components and simulate your real-time environment.

A Simulink model that has been redesigned after requirements validation. Below the model, the verification statuses of listed requirements are colored green to indicate that all the model properties are valid.

Validate Designs with Simulink

Stateflow integrates seamlessly with other MathWorks products to verify, validate, and test your designs. You can leverage these products to ensure your designs satisfy requirements, find errors earlier, and meet quality objectives.

Two application windows connected by a graphic that indicates the second window was created from the first. The first window shows a Stateflow chart and the second shows C code that was automatically generate from the chart.

Generate Code for Deployment

Code generation allows you to implement your state chart logic on embedded systems. Stateflow supports workflows to generate C, C++, VHDL, and Verilog code as well as Structured Text for PLCs.

“Until Deep Space 1, state charts and automatic code generation technology had not been used on large systems for spacecraft avionics software. MathWorks tools made this approach possible.”

Stateflow FAQs

You can design and develop supervisory control systems, fault detection, isolation and recovery systems, and task scheduling and event management embedded systems.

Stateflow charts and tables can be used in Simulink as a block and exchange data through input and output ports. You can also embed Simulink subsystems as states and functions within Stateflow. Stateflow can also invoke components in Simulink, acting as a task scheduler for Simulink components. Stateflow uses MATLAB syntax to define state actions, transitions, and conditions. Stateflow can also invoke MATLAB Functions to perform complex calculations or reuse existing MATLAB code.

Stateflow provides graphical animation that highlights active states and transitions during execution, and you can set breakpoints to step through chart execution in detail. You can also manually modify variables during execution to visualize their impact on the system.

Stateflow supports code generation for C, C++, VHDL, Verilog, and Structured Text for PLCs, allowing you to implement your state chart logic on embedded systems.

State Transition Tables offer a tabular view for modeling logic and are an ideal solution for simple, process-oriented, sequential state machines.

Yes, Stateflow can invoke Simulink algorithms in a periodic or continuous manner to schedule the execution of components and simulate your real-time environment.

You can use the Symbols Pane UI to inspect data during simulation, and you can also use Simulation Data Inspector to visualize simulation data and monitor a system across runs to gather valuable insights on its behavior.

Interested in Stateflow?


Ready to Buy?

Get pricing information and explore related products.

Are You a Student?

Your school may already provide access to MATLAB, Simulink, and add-on products through a campus-wide license.