Contents

Using Simulink® Functions in Stateflow®

This model shows a simple use of Simulink functions in Stateflow. Starting from R2008b, you can use Simulink function call subsystems in Stateflow just like other function objects such as Graphical functions, MATLAB™ functions and Truth Table functions.

With Simulink functions

The chart WithSimulinkFunctions shows the use of Simulink functions algo1() and algo2() directly within Stateflow.

Note the following:

  1. We can use multiple outputs syntax to communicate multiple outputs/inputs to the Simulink subsystem.

  2. Using C as the action language, you can call a Simulink Function directly from a Stateflow expression.

Without Simulink functions

The chart WithoutSimulinkFunctions shows how a similar functionality would have been achieved without the use of Simulink functions in previous releases.

Note the following:

  1. You need to create multiple function call output events in order to communicate with the Simulink subsystems.

  2. You have to manually connect up the inputs/outputs from the Simulink subsystems to the Stateflow chart.

  3. You cannot use the output from a Simulink subsystem directly in an expression. You have to first write to the corresponding outputs, send() the output event, and then read back from the corresponding inputs.

Advantages of using Simulink functions

Directly using Simulink functions in Stateflow rather than using function call output events has several advantages:

  1. It is less error-prone since there is much less wiring.

  2. Using C as the action language, you can call a Simulink Function directly from a Stateflow expression.

  3. The design hierarchy is much more evident when the Stateflow chart contains the Simulink subsystems which it uses.

Was this topic helpful?