The scope of a Simulink® function is defined in the context of a model. If you place a function at the
root level of a model, the function is scoped to the model by default. The
Trigger block parameter Function visibility is set
scoped, and access to the function from outside the model is possible
Access the function from:
Within the model without qualifying the function name.
Outside the model by qualifying the function name with the model instance name.
Setting Function visibility for a Simulink Function
global allows you to access the function from anywhere in a
model or the parent model. As a result, models with a Simulink Function block
set to global cannot be multi-instanced because function names must be unique.
Placing a Simulink Function block within a model at the root level limits access to the function and removes the function name from the global namespace. You can call the function from inside the model without qualification. For example:
y = function_name(x)
The function caller can be:
At the same hierarchic level as the function
In a subsystem or model one or more levels below the hierarchic level of the function
You cannot place a function caller inside a Model block and the Simulink Function block in the parent model,
If you place a function caller inside a Model block, Simulink displays an error. This error occurs because the model containing the caller does not know the name of the function.
When you place a Simulink Function block in a Model block, the function name is not accessable outside the model. To call the function from outside the model, qualify the function name with the model block name in the parent model. For example:
y = model01.function_name(x)
A function caller can be at a level where it can hierarchically resolve to the model instance containing the function:
The function caller can be outside the model one hierarchic level above the function.
You cannot place a Simulink Function block in one Model block and the function caller in another Model block..
If you place a Simulink Function block in a referenced model and a function caller in another referenced model, Simulink displays an error. This error occurs because the qualified function name using the Model block name is not visible to the model containing the caller.
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 Seperate Models in the topic Simulink Functions in Referenced Models.
Setting Function visibility for a Simulink
Function block to
scoped allows you to multi-instance a
model containing the function. This model behavior is allowed because the function is
encapsulated within the model. Adding the model instance name to the function name
creates a qualified function name that is unique within the parent model.
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
Reference the model with Simulink functions from multiple Model blocks. Add a Function-Call Subsystem block to schedule calls to the functions.
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.
From the Display menu, select Function Connectors. 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 Modeling Reusable Components Using Multiply Instanced Simulink Functions.