Configure Variant Parameter Values for Instances of Referenced Models - MATLAB & Simulink (original) (raw)

Main Content

A model reference is a reference to another model using a Model block. You can reuse a model multiple times by referring to it with multipleModel blocks. These references create a model hierarchy. You can then configure a block parameter (such as the Gain parameter of aGain block) to use either the same value or a different value for each instance of the model. To set different values for the same parameter across multiple model instances, create and use a model argument. For more information, see Configure Instance-Specific Values for Block Parameters in a Referenced Model.

Variant parameters enable you to conditionally vary the values of block parameters in a Simulink® model. Use the Simulink.VariantVariable class to create a variant parameter object. You create a variant parameter object in the base workspace, model workspace, or in the Design Data section of a Simulink data dictionary. For an example, see Create a Simple Variant Parameter Model.

Define Variant Parameters in Model Workspace for Use in Referenced Models

A model workspace effectively provides a model with its own namespace, allowing you to create variables for the model without risk of conflict with other models. When you define variant parameters in the model workspace, set the ActivationTime property of the Simulink.VariantControl object used as the variant control variable to update diagram,update diagram analyze all choices, orstartup. The objects associated with the variant parameter object, such as the Simulink.VariantControl object, the Simulink.Parameter object used to set the Specification property, and any Simulink.Parameter objects used as values of the variant parameter, must be defined in the model workspace along with the parameter.

In a model reference hierarchy, you can define variant parameters with the same name but with different values scoped to the model workspaces of the referenced models.

In this example, the referenced models mModelWksRefModelA andmModelWksRefModelB each use variant parameters K andkv, and a variant control variable V defined in their respective model workspaces. In mModelWksRefModelA,V is set to 1 and inmModelWksRefModelB, V is set to2. The top-level model mModelWksTopModel definesK and V in the base workspace withV set to 3.

mModelWksTopModel with a constant block that uses variant parameter K and two Model blocks that refer to mModelWksRefModelA and mModelWksRefModelB. Both mModelWksRefModelA and mModelWksRefModelB have the same model hierarchy with two variant parameters K and kv.

This image shows the results of activating the workspace variant configuration for the model mModelWksTopModel from Variant Manager. The active choice for the variant parameter in each model depends on the value of V in the corresponding workspace. For information on managing variant parameters, see Manage Variant Parameters Using Variant Manager.

Variant Parameters tab in Variant Manager shows the results of activating the variant parameters. The active choice is highlighted for the parameters in each of the workspaces.

Specify Instance-Specific Values for Variant Parameters in a Referenced Model

To configure a variant parameter in the referenced model to use a different value for each instance of the model, configure the Simulink.VariantControl object defined in the model workspace of the referenced model as a model argument by selecting the Argument property in the Model Explorer. In each Model block that refers to this model, specify an instance-specific value for the variant control from the Block Parameters dialog box.

Open the model slexVariantParameterMultiInstance and the referenced model slexVariantParameterWiper.

open_system("slexVariantParameterMultiInstance"); open_system("slexVariantParameterWiper");

Simulate the model. Open the Simulation Data Inspector and compare the logged signals to see how the output varies for different instances of the same referenced model.

See Also

Simulink.VariantVariable | Simulink.VariantControl

Topics