Main Content

Scoped, Global, and Port-Scoped Simulink Function Blocks Overview

Defining the visibility of functions can help you to avoid name space conflicts when integrating your referenced models. A Simulink Function block defines the visibility of its function in relationship to the subsystem or model containing the block as either scoped, global, or port-scoped. By default, Simulink Function blocks are scoped.

  • Function Visibility. A scoped function is visible in its hierarchy. A function caller located at the same level as the function, or one or more levels below can refer to the function. A global function is visible across a model hierarchy. This means that a function caller located anywhere in the current model or in the parent model hierarchy can refer to the function. A port-scoped function is visible only to a particular exporting function port in the current model, and is not visible elsewhere in the model hierarchy. The function can be called only from outside the current model, and only through the exporting function port.

  • Function accessibility is determined by the visibility of a function and the location of the function caller relative to the Simulink Function block. For function callers one hierarchical level above the function, qualify the function name with the virtual Subsystem block name or Model block name.

  • Function exporting refers to functions exported from models. A function with global visibility, placed anywhere in an export-function model, is exported to the top level of a model hierarchy in addition to the model interface. A function with scoped visibility at the root level of an export-function model is exported to the model interface. In both these cases, you can access the exported function outside of the model. A function with port-scoped visibility must be placed at the root level of an export-function model, and can be accessed by function callers in other export-function models only through a connection between function ports in the respective models.

Use the Function visibility parameter for the Trigger block within a Simulink Function block to set the function visibility to either scoped, global, or port. For a port-scoped function, specify the name of the port in the Scope to port field.

Summary of Simulink Function Block Visibility and Access

Simulink Function BlockFunction VisibilityFunction AccessibilityFunction Exporting
Virtual Subsystem

scoped

Function names at the same hierarchical level must be unique.

Function caller inside hierarchy or at parent level.

Function caller inside Subsystem block hierarchy – Unqualified, fcn(). See Resolve to a Function Hierarchically in Scoped Simulink Function Blocks in Subsystems.

Function caller at parent level – Qualified with subsystem block name, subsystem.fcn(). See Resolve to a Function by Qualification in Scoped Simulink Function Blocks in Subsystems.

Does not apply.

global

Function name must be unique.

Function caller at any level of hierarchy down or up.

Function caller at any level of hierarchy – Unqualified, fcn().

Function at any level of model exported to the global name space of the top-level model.

port visibility not allowed.

Does not apply.

Does not apply.

Atomic Subsystem

scoped

Function names at the same hierarchical level must be unique

Function caller only inside hierarchy

Function caller inside Subsystem block hierarchy – Unqualified, fcn(). See Resolve to a Function Hierarchically in Scoped Simulink Function Blocks in Subsystems.

Function caller at parent level – not allowed.

Does not apply.

global visibility not allowed.

Function call not allowed.

Does not apply.

port visibility not allowed.

Does not apply.

Does not apply.

Model

scoped

Function names must be unique at the model root level.

Function caller inside hierarchy or at parent level.

Function caller inside Subsystem block hierarchy – unqualified, fcn(). See Resolve to a Function Hierarchically in Scoped Simulink Function Blocks in Models.

Function caller at parent level – Qualified with Model block name, model_block.fcn(). See Resolve to a Function by Qualification in Scoped Simulink Function Blocks in Models.

Function at the root level of a model exported to the model interface.

global

Function name must be unique.

Function caller at any level of hierarchy down or up.

Function caller at any level of hierarchy – Unqualified, fcn().

Function at any level of model exported to the global name space of the top-level model.

port

Function names at the model root level do not have to be unique if scoped to different ports.

Function caller associated with invoking function port connected to exporting function port to which function is scoped. Qualified with invoking port name, PortName.fcn().

For more information, see Model Client and Server Components Using Function Ports.

Function not visible except through exporting function port.

See Also

Blocks

Related Topics