Where to Define a Simulink Function in a Chart

A Simulink® function can reside anywhere in a chart, state, or subchart. The location of a function determines its scope, that is, the set of states and transitions that can call the function. Follow these guidelines:

  • If you want to call the function only within one state or subchart and its substates, put your Simulink function in that state or subchart. That function overrides any other functions of the same name in the parents and ancestors of that state or subchart.

  • If you want to call the function anywhere in that chart, put your Simulink function at the chart level.

You can also define Simulink functions in a Simulink Function block at the top level of a model. These functions can interact with both Simulink and Stateflow®. For more information, see Simulink Function and Functions and Function Callers.

Was this topic helpful?