Scoped Simulink Function Blocks in Models - MATLAB & Simulink (original) (raw)

Main Content

The scope of a Simulink® function is defined in the context of a model. If you place a Simulink Function block in a model at the root level, the function is scoped to the model by default. The Trigger block Function visibility parameter is set to scoped. Access the function with a function caller located:

Setting Function visibility for a Simulink Function block to global allows you to access the function from anywhere in the model or a parent model. As a result, models with a Simulink Function block set to global cannot be multi-instanced because function names must be unique.

Resolve to a Function Hierarchically

Placing a scoped Simulink Function block within a model at the root level limits access to the function and removes the function name from the global name space.

Resolve to a Function by Qualification

When you place a Simulink Function block in a Model block, the function name is not accessible outside the model. However, you can call a function by qualifying the function name with the Model block name. When a function caller resolves to a qualified function hierarchically, it looks for the Model block containing the function using the following rules:

If a function caller resolves to a Model block with a scoped function, you can call the function by qualifying the function name:

If you want to access the function using this modeling pattern, see the section Function Caller Block in Referenced Model and Function and the section Function Caller in Separate Models in the topic Simulink Function Blocks in Referenced Models.

Setting Function visibility for a Simulink Function block to scoped encapsulates the function within the model, allowing you to multi-instance the model. Adding the model instance name to the function name creates a qualified function name that is unique within the parent model.

  1. Create a model containing Simulink Function blocks.

    By default, the Function visibility parameter for the Trigger block within the Simulink Function block is set to scoped.
  2. Reference the model with Simulink functions from multiple Model blocks. Add a Function-Call Subsystem block to schedule calls to the functions.
  3. Add Function Caller blocks to the Function-Call Subsystem block. Access the function in separate model instances by qualifying the function name with the block name.
  4. On the Debug tab, under Information Overlays , click Connectors. Select Function Connectors option from the Connectors pane that appears on the Simulink canvas.
    Tracing lines are drawn to help you navigate from a function caller to the function.

For a model using Simulink Function blocks with multiple instances, see Reuse Multiple Instances of a Simulink Function.

See Also

Simulink Function | Argument Inport | Argument Outport | Function Caller | MATLAB Function

Topics