Reduce Model Containing Variant Parameters
This example shows how to reduce a Simulink® model that contains variant parameters using Variant Reducer in Variant Manager. The example explains the reduction process for these scenarios:
a. Reduction of these types of variant parameter objects for a single variant configuration:
With numeric values
With values of type
With the Specification property set
b. Reduction of variant parameters for multiple variant configurations
Variant parameters enable you to vary the values of block parameters in a Simulink model conditionally. You create a variant parameter as an object of type
Simulink.VariantVariable. This object defines the set of possible values for a parameter and a variant condition expression associated with each value. After creating the object, you can use it to set the value of block parameters in a model, such as the Gain parameter of a Gain block. During simulation, the value associated with the variant condition that evaluates to
true becomes the active value of that parameter. The values associated with the conditions that evaluate to
false become inactive. For more information, see Use Variant Parameters to Reuse Block Parameters with Different Values.
Using Variant Reducer, you can generate a reduced model that retains only the selected variant configurations that you choose from the parent variant model. The tool removes the model components that are inactive in the specified variant configurations and packages the reduced artifacts into a user-specified output folder. In the case of variant parameters, the reduction process retains only the specified values from the
Simulink.VariantVariable objects and removes the remaining inactive choices based on the input configurations that you specify.
For more information on Variant Reducer, see Reduce Variant Models Using Variant Reducer.
1. Open the model
The model contains two
Gain blocks. The Gain parameters of the blocks are set to the variant parameter objects
2. Open the
slexVariantParameterData.m file to see the definitions of objects used by this model.
K2are defined as objects of type
K2have two choices. The choices have numeric
doublevalues and a variant condition expression associated with each value.
The variant condition is defined using a
V, with value set to
1. During simulation, the value of
Vdetermines the active value of the variant parameter objects
The objects get created in the base workspace of the model during model load.
K2in the MATLAB® workspace to view their possible values.
This example additionally refers to these type of variant parameters that are not present in the
Variant parameters that have
Simulink.Parameterobjects as choice values
Variant parameters with an associated Specification, which helps you to set properties of the object such as data type, dimensions and storage class.
For example, this variant parameter has the values
kp2, which are names of
Open Variant Reducer
1. Open Variant Manager. On the Modeling tab, open the Design section and click Variant Manager.
2. To open Variant Reducer, in the Variant Manager toolstrip, in the Apps section, click Variant Reducer.
Choose Reduction Mode
The Reduction mode option in Variant Reducer provides multiple ways to specify the configurations that you want to retain in the reduced model. You can select single or multiple named variant configurations created for the model, or you can directly specify the required variant control variables and their values by defining variable groups.
When you reduce a variant parameter object for a single configuration, you specify only a single choice of the object that must be retained in the reduced model. The reduced object will have only one value without any variant capability. So, based on the type of value the variant parameter object has, the reduction process converts it into a normal MATLAB® variable with a numeric value or into a
When you reduce a variant parameter object for multiple configurations, the reduction process retains the configurations that you specify in the reduced model. The process does not convert the
Simulink.VariantVariableobject to any other type.
Reduce Model for Single Variant Configuration
In the Variant Reducer window for the example model, the Variable Groups tab opens by default because there are no named configurations defined for the model. The Group table shows the current value of the variant control
1. In the example, choices of
K2 have numeric
1. Specify the values for different reduction options as needed in the Options section of the toolstrip.
2. Click Reduce Model. Variant Reducer reduces the model for the condition
3. Observe the objects
K2 in the base workspace. You can see that
K2 are converted to normal MATLAB variables of type
double, with values corresponding to the condition
Instead, if the choice value of the variant parameter is a
Simulink.Parameter object, then after reduction the variant parameter object is converted into a
Simulink.Parameter object with values and properties based on the selected choice.
Variant Parameter Object with Specification
If the variant parameter object has the Specification property set, then these changes apply for single configuration reduction:
A variant parameter object with a numeric choice value is converted into a
Simulink.Parameterobject that has a value based on the selected configuration and remaining properties derived from the Specification property of the variant parameter object.
A variant parameter object with choice value set to a
Simulink.Parameterobject is not converted to any other type. It remains of type
Simulink.VariantVariableand retains the selected configuration and Specification.
Reduce Model for Multiple Configurations
Close the reduced model and open the
slexVariantParameters model again.
1. In the base workspace, double-click the variant parameter object
K1. In the
Simulink.VariantVariable dialog box, add one more choice to
K1 with Condition as
V==3 and Value as
10.5. Repeat this step for
2. Open Variant Reducer for the model.
3. In the Variable Groups tab, specify the value for
4. Click Reduce Model. Variant Reducer reduces the model for the conditions
5. Observe the objects
K2 in the base workspace. You can see that they are variant parameter objects with two choices corresponding to
Reduce Model Programmatically
Reduce the model programmatically for the single configuration specified by the condition
Reduce the model for multiple configurations specified by the conditions
Reduce the model by specifying a named variant configuration that is present in the variant configuration data object associated with the model.
Summary of Variant Parameter Reduction
In a single configuration reduction, variant parameters convert as follows:
a. Without a Specification:
A variant parameter with numeric choice values converts to a normal MATLAB variable of same data type.
A variant parameter with
Simulink.Parameterobjects as choice values converts to
Simulink.Parameterobject with values and properties based on the selected configuration.
b. With a Specification:
A variant parameter with numeric choice values converts to a
Simulink.Parameterobject that has values based on the selected configuration and remaining properties derived from the Specification property of the variant parameter object.
A variant parameter with
Simulink.Parameterobjects as choice values remains as a variant parameter object with the same Specification and
Simulink.Parameterobjects as values, based on the selected configuration.
In a multiple configuration reduction, the model retains the variant parameter object with the selected configurations and Specification, if available.
NOTE: Specifying the value of a variant control variable as
full-range during reduction is not supported if the variable is used by variant parameters visible to the model, even if the parameter is not used in the model hierarchy.