Main Content

Scoped Simulink Function Blocks in Models

The scope of a Simulink®function is defined in the context of a model. If you place a金宝app仿真软件的功能block in a model at the root level, the function is scoped to the model by default. TheTriggerblockFunction visibilityparameter is set toscoped. Access the function with a function caller located:

  • Within the model hierarchy containing the function. Call the function without qualifying the function name.

  • Outside the model. Call the function by qualifying the function name with the model block instance name, not the model file name.

SettingFunction visibilityfor a金宝app仿真软件的功能block toglobalallows you to access the function from anywhere in the model or a parent model. As a result, models with a金宝app仿真软件的功能block set to global cannot be multi-instanced because function names must be unique.

Resolve to a Function Hierarchically

Placing a scoped金宝app仿真软件的功能block within a model at the root level limits access to the function and removes the function name from the global name space.

  • Function caller located in the current model.

  • You cannot place a function caller inside aModelblock and the金宝app仿真软件的功能block in the parent model,

    If you place a function caller inside aModelblock, Simulink displays an error. This error occurs because the model containing the caller does not know the name of the function. Function calls cannot cross model reference boundaries.

决心Qualifi函数cation

When you place a金宝app仿真软件的功能block in aModelblock, the function name is not accessible outside the model. However, you can call a function by qualifying the function name with theModelblock name. When a function caller resolves to a qualified function hierarchically, it looks for theModelblock containing the function using the following rules:

  • Resolution Rule 1: Is theModelblock in the current model with the function caller?

  • Resolution Rule 2: If theModelblock is not in the current model or subsystem, is theModelblock in a parent or grandparent model one or more levels above the function caller?

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

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

  • 函数调用者在一个子系统hierarc相同hic level as the function. In this case, the function caller didn't find theModelblock in the current subsystem, but it found the Model block in the parent model (Resolution Rule 2).

  • You cannot place a Simulink Function block in one Model block and the function caller in another Model block.

    If you place a金宝app仿真软件的功能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 theModelblock 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 Separate Models in the topic金宝app仿真软件的功能Blocks in Referenced Models.

Multi-Instance Modeling with Simulink Functions

SettingFunction visibilityfor a金宝app仿真软件的功能block toscopedencapsulates 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金宝app仿真软件的功能blocks.

    By default, theFunction visibilityparameter for theTriggerblock within the金宝app仿真软件的功能block is set toscoped.

  2. Reference the model with Simulink functions from multipleModelblocks. Add aFunction-Call Subsystemblock to schedule calls to the functions.

  3. AddFunction Callerblocks to theFunction-Call Subsystemblock. Access the function in separate model instances by qualifying the function name with the block name.

  4. On theDebugtab, selectInformation Overlays. From the drop-down box, selectFunction 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, seeModeling Reusable Components Using Multiply Instanced Simulink Functions.

See Also

Blocks

Related Topics