This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Flow Charts in Stateflow

A Stateflow® flow chart is a graphical construct that models logic patterns such as decision trees and iterative loops. Flow charts represent combinatorial logic in which one result does not depend on prior results. You build flow charts by combining connective junctions and transitions without using any states. The junctions provide decision branches between different transition paths. Executing a flow chart begins at a default transition and ends at a terminating junction (a junction that has no valid outgoing transitions).

A best practice is to encapsulate flow charts in graphical functions to create modular and reusable logic that you can call anywhere in a chart. For more information about graphical functions, see Reuse Logic Patterns by Defining Graphical Functions.

An example of a flow chart that models simple if-else logic:

The flow chart models this code:

if u > 0
   y = 1;
else
   y = 0;
end

Draw a Flow Chart

You can draw and customize flow charts manually by using connective junctions as branch points between alternate transition paths:

  1. Open a chart.

  2. From the editor toolbar, drag one or more connective junctions into the chart with the Connective Junction tool:

  3. Add transition paths between junctions.

  4. Label the transitions.

  5. Add a default transition to the junction where the flow chart execution starts.

Best Practices for Creating Flow Charts

Follow these best practices to create efficient, accurate flow charts:

 Use only one default transition

 Provide only one terminating junction

 Converge all transition paths to the terminating junction

 Provide an unconditional transition from every junction except the terminating junction

 Use condition actions to process updates, not transition actions

An example that illustrates these best practices:

Related Examples

More About