Main Content

Scoped Simulink Function Blocks in Subsystems

The scope of a Simulink® function is defined in its parent subsystem within the context of a model. If you place a function in any Subsystem block, access to the function from outside the model is prohibited by default. In both cases, the Trigger block Function visibility parameter is set to scoped. The Simulink Function block can be located:

  • In a virtual subsystem — Call the function from within the containing Subsystem block hierarchy without qualifying the function name, or call the function from outside the subsystem by qualifying the function name with the subsystem block name.

  • In an atomic or non-virtual subsystem — Call the function from within the containing Subsystem block hierarchy without qualifying the function name. Accessing the function from outside of the subsystem is prohibited.

Resolve to a Function Hierarchically

Placing a scoped Simulink Function block within any Subsystem block (virtual or atomic) limits access to the function and removes the function name from the global name space. When a function caller resolves to a function hierarchically, it looks for the function using the following rules:

  • Resolution Rule 1: Is the scoped Simulink Function block in the current Subsystem block with the function caller?

  • Resolution Rule 2. If the scoped function is not in the current subsystem, is the scoped Simulink Function block in a parent or grandparent Subsystem block one or more levels above the function caller, or in a parent Model?

If a function caller resolves to a function hierarchically, you can call the function without qualifying the function name:

  • Function caller located at the same hierarchic level as the function. In this case, the function caller finds the scoped function in the current subsystem (Resolution Rule 1).

  • Function caller located in a Subsystem block one or more Subsystem block levels below the hierarchic level of the Simulink Function block. The function caller hierarchy cannot include a Model block since the function caller cannot cross model reference boundaries. In this case, the function caller didn't find the scoped function in the current subsystem, but it found the function in the parent subsystem (Resolution Rule 2).

    In this case, the function caller didn't find the scoped function in the current subsystem, but it found the function in the parent model (Resolution Rule 2).

  • You can also call a Simulink Function block in a Subsystem block without qualification from a MATLAB Function block or a Stateflow® chart within the block.

Resolve to a Function by Qualification

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

  • Resolution Rule 1: Is the virtual Subsystem block in the current component with the function caller? A component can be a Subsystem block or Model.

  • Resolution Rule 2. If the virtual Subsystem block is not in the current component, is the virtual Subsystem block in a parent or grandparent component one or more levels above the function caller?

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

  • Function caller located outside of the subsystem one hierarchic level above the function. In this case, the function caller finds the Subsystem block with the scoped function in the current model (Resolution Rule 1).

  • Calling the function from a Stateflow chart outside the subsystem one hierarchic level above the function. In this case, the function caller finds the Subsystem block with the scoped function in the current model (Resolution Rule 1).

  • Function caller is in another subsystem at the same hierarchic level as the function. In this case, the function caller didn't find the Subsystem block with the scoped function in the current subsystem, but it found the Subsystem block in the parent model (Resolution Rule 2).

  • Function caller is in another subsystem one or more subsystem levels below the hierarchic level of the function. In this case, the function caller didn't find the Subsystem block with the scoped function in the current subsystem, but it found the Subsystem block in the grandparent model (Resolution Rule 2).

    The function caller hierarchy cannot include a Model block since the function caller cannot cross model reference boundaries.

See Also

| | | | |

Related Topics