Integrating Components and Scheduling Algorithms

After creating components in Stateflow, you can integrate them with other components to build your state machine algorithm. Stateflow components can contain MATLAB and Simulink functions, custom C code, graphical functions, and truth tables. In your algorithm, you can schedule component and function execution using time-based and condition-based logic.

Each Stateflow component can be developed, executed, and verified independently, enabling multiple users to work on different parts of the algorithm at the same time.

Simulink model  incorporating a Stateflow diagram that uses graphical functions, MATLAB functions, and truth tables.
Simulink model (left) incorporating a Stateflow diagram (right). The Stateflow diagram models the logic used in an elevator and includes graphical functions, MATLAB functions, and truth tables.

Integrating Components into your Design

You can reuse a component across diagrams and models by right-clicking it, converting it to an atomic subchart, and placing it in a library. To use the component, you drag it from the library and drop it into your diagram or model. When you update a component in the library, all instances of the component are automatically updated. You can organize components and functions hierarchically to represent your system concisely and accurately.

Reusing States Multiple Times in a Diagram 3:47
Create and reuse components in Stateflow for large-scale modeling.


Scheduling Algorithms

You can model conditional and time-based logic in Stateflow to call Simulink functions and MATLAB functions. Events based on logic modeled in Stateflow can be output to Simulink to activate subsystems that react to a function call or to changes in the control signal.

Stateflow provides event-based and time-based operators (before, after, at, and every) that let you specify state-transition logic based on event counts and elapsed time without using timers and counters.

Schedule Execution of Simulink Subsystems 3:38
Use time-based and condition-based logic to schedule Simulink® functions.

Next: Simulating a Model and Analyzing the Results

Try Stateflow

Get trial software

Mobile Robot Simulation for Collision Avoidance with Simulink

View webinar

Learn to Create and Debug State Logic for Simulink Models

Get more info