Use Variant Parameters to Reuse Block Parameters with Different Values - MATLAB & Simulink (original) (raw)

Main Content

You may have a set of requirements where the structure of the model remains the same, but the values of the parameters for each requirement are different. In this scenario, you can create a single model with fixed structure and create parameters with a finite set of values where each value corresponds to different requirements. Parameters that have multiple values are called variant parameters. Use the Simulink.VariantVariable class to create a variant parameter object.

Each value of a variant parameter must be associated with a variant condition expression. You can have multiple variant parameters associated with a variant condition, provided no two values belong to the same parameter. When a condition expression evaluates totrue, all the values associated with that condition become active and are assigned to the corresponding parameters. If you change the value of the variant control variable, a different set of values is assigned to the parameters. This way, variant parameters allow you to logically bind a set of values across different parameters to a condition expression, and the values are assigned to the parameter based on the variant condition that evaluates to true.

SimulinkĀ® selects the active value of a variant parameter during update diagram time, during code compile time, or during the model startup time. For more information, see Activate Variant During Different Stages of Simulation and Code Generation Workflow.

Consider this model. The Gain parameter of the Gain block is a variant parameter with its value set to K. The variable_K_ has two values: 3.5 and 8.5. Simulink chooses active value of K based on the value of the variant control variable V. If V==1 evaluates totrue, the value of K is set to 3.5. If V==2 evaluates to true, the value of_K_ is set to 8.5.

Variant parameter with multiple values in a Gain block. Each value is associated with a variant condition expression.

When to Create Variant Parameters

Variant parameters provide a way to design one model for many systems that differ in block parameter values. You can group different sets of values based on the system to simulate. Each set of values is associated with a variant condition expression. During simulation, if a variant condition evaluates to true, then all the values associated with that condition become active. To change the set of active values, change the value of the variant control variable and run the simulation again.

Consider this model that represents an automobile system with several configurations. These configurations, although similar in several aspects, can differ in values such as fuel consumption, engine size, or number of cylinders in the engine. Instead of designing multiple blocks that together represent all possible values, you can use variant parameters to model the varying values.

An example of how you can use variant parameters in a model to represent an automobile system with several configurations

In this model, the Fuel consumption, Engine size, and Number of cylinders have variant parameters fc, es, and nc. The values of the variant parameters are based on the value of the variant control variableV. For example, if V==1 evaluates totrue, then the value of fc is set to30, es is set to 1000, andnc is set to 4.

Advantages of Using Variant Parameters

Using variant parameters in Model-Based Design provides several advantages:

Limitations

See Also

Simulink.VariantVariable | Simulink.VariantControl | Simulink.VariantBank

Topics