Documentation Center

  • Trial Software
  • Product Updates

Why Use a Simulink Function in a Stateflow Chart?

Advantages of Using Simulink Functions in a Stateflow Chart

When you define a function that uses Simulink® blocks or schedule execution of multiple controllers without Simulink functions, the model requires these elements:

  • Simulink function-call subsystem blocks

  • Stateflow® chart with function-call output events

  • Signal lines between the chart and each function-call subsystem port

Simulink functions in a Stateflow chart provide these advantages:

  • No function-call subsystem blocks

  • No output events

  • No signal lines

For details about each modeling method, see Benefits of Using a Simulink Function to Access Simulink Blocks and Benefits of Using a Simulink Function to Schedule Execution of Multiple Controllers.

Benefits of Using a Simulink Function to Access Simulink Blocks

The sections that follow compare two ways of defining a function that uses Simulink blocks.

Model Method Without a Simulink Function

You define a function-call subsystem in the Simulink model (see Create a Function-Call Subsystem. Use an output event in a Stateflow chart to call the subsystem, as shown.

Model Method With a Simulink Function

You place one or more Simulink blocks in a Simulink function of a Stateflow chart. Use a function call to execute the blocks in that function, as shown.

In the chart, the during action in selection_state contains a function call to calc_th, which is a function that contains Simulink blocks.

This modeling method minimizes the objects in your model.

For more information, see Define a Function That Uses Simulink Blocks.

Benefits of Using a Simulink Function to Schedule Execution of Multiple Controllers

The sections that follow compare two ways of scheduling execution of multiple controllers.

Model Method Without Simulink Functions

You define each controller as a function-call subsystem block and use output events in a Stateflow chart to schedule execution of the subsystems, as shown.

Model Method With Simulink Functions

You define each controller as a Simulink function in a Stateflow chart and use function calls to schedule execution of the subsystems, as shown.

This modeling method minimizes the objects in your model.

For more information, see Schedule Execution of Multiple Controllers.

Was this topic helpful?