State actions and transition conditions can be complicated enough that defining them inline on the state or transition is not feasible. In this case, express the conditions or actions using one of the following types of Stateflow® functions:
Flow chart — Encapsulate flow charts containing if-then-else, switch-case, for, while, or do-while patterns. For more information, see Reuse Logic Patterns by Defining Graphical Functions.
MATLAB — Write matrix-oriented algorithms; call MATLAB functions for data analysis and visualization. For more information, see Reuse MATLAB Code by Defining MATLAB Functions.
Simulink — Call Simulink function-call subsystems directly to streamline design and improve readability. For more information, see Reuse Simulink Components in Stateflow Charts.
Truth table — Represent combinational logic for decision-making applications such as fault detection and mode switching. For more information, see Reuse Combinatorial Logic by Defining Truth Tables.
Use the function format that is most natural for the type of calculation required in the state action or transition condition.
If the four standard types of Stateflow functions do not work, you can write your own C or C++ code for integration with your chart. For more information about custom code integration, see Reuse Custom Code in Stateflow Charts.