Skip to Main Content Skip to Search
Product Documentation

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 functions in a Stateflow chart provide these advantages:

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.

Modeling Method Without a Simulink Function

You define a function-call subsystem in the Simulink model (see Function-Call Subsystems in Simulink User's Guide). Use an output event in a Stateflow chart to call the subsystem, as shown.

Modeling 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 Defining 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.

Modeling 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.

Modeling 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 Scheduling Execution of Multiple Controllers.

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS