Add or Remove Variant Choices of Variant Assembly Component Blocks Using External File
A Variant Assembly Component block can use Model blocks, Subsystem Reference blocks, or both as its variant choices. The variant choices are maintained in a separate model and subsystem files that are on the MATLAB®path. You can add or remove the variant choices from the Variant Assembly Component block without modifying the model. You use an external source such as an enumeration class or a MATLAB function to manage the variant choices of the Variant Assembly Component block. Unlike when you use Variant Component blocks, you are not required to navigate inside the Variant Assembly Component block to add or remove the variant choices from the block. For more information, see Variant Assembly Component in Variant Component. This example explains how to manipulate Variant Choices of Variant Assembly Component Block in Label and Expression Modes.
Open Model
The model slexVariantAssemblyComponent
contains two Variant Assembly Component blocks Controller1
in label mode and Controller2
in expression mode.
In this example, the vacLinearController1 and vacLinearController2
are Model Reference blocks. The vacNonLinearController1 and vacNonLonlinearController2
are Subsystem Reference blocks. The choices are saved as subsystem or model files in your current working folder.
systemcomposer.openModel('slexVariantAssemblyComponent.slx');
Manipulate Variant Choices of Variant Assembly Component Block in Label Mode
To add variant choices to the Controller1
block, right-click the variant badge on the block icon and select Block Parameters. Specify this MATLAB expression in the Variant choices specifier parameter.
{'*Controller*'}
Explore the Controller1
block to observe the four variant choices vacLinearController1
, vacLinearController2
, vacNonLinearController1
, and vacNonLinearController2
that are added to the Controller1
block. The file name and the path of the newly added variant choices are displayed in the Variant Choices table in the Reference tab.
From Label mode active choice, select vacLinearController1
and simulate the model. Observe that the vacLinearController1
choice becomes active.
You can modify the expression in the Variant choices specifier parameter as described in Specify Variant Choices of Variant Assembly Subsystem Block in Variant Choices Specifier Parameter, then simulate the model again.
Manipulate Variant Choices of Variant Assembly Component Block in Expression Mode
The vacLinearController1
and vacNonLinearController1
blocks are added as choices to the Controller2
block using enumerations. Explore the Controller2
block to observe the two variant choices vacLinearController1
, and vacNonLinearController1
are added to the Controller2
block.
To configure the Controller2
block, set the Variant control variable parameter to 'V'
and the Variant choices enumeration parameter to ControllersEnum
in the Block Parameters dialog box. For more information on how the enumerations are defined, see Manipulate Variant Choices of Variant Assembly Subsystem Block in Expression Mode.
mdl = 'slexVariantAssemblyComponent'; open_system(mdl) vacBlkPath = [mdl,'/Controller2'];
To configure the Controller
block, set the Variant control variable parameter to variantCtrlVar
and the Variant choices enumeration parameter to controllerTypesMFile
in the Block Parameters dialog box.
set_param(vacBlkPath, 'VariantChoicesEnumeration','ControllersEnum') set_param(vacBlkPath, 'VariantControlVariable','V')
To activate the vacLinearController1
choice, set 'V'
to ControllersEnum.vacLinearController1
and then simulate the model. During simulation, the V == ControllersEnum.vacLinearController1
expression evaluates to true
. Subsequently, the vacLinearController1
choice becomes active.
V = ControllersEnum.vacLinearController1; sim(mdl);
Similarly, to activate the vacNonLinearController1
choice, set 'V'
to ControllersEnum.vacNonLinearController1
and simulate the model again.
V = ControllersEnum.vacNonLinearController1; sim(mdl);
See Also
Blocks
Objects
Functions
addChoice
|addVariantComponent
|getActiveChoice
|getChoices
|getCondition
|makeVariant
|makeVariantAssembly
|setActiveChoice
|setCondition
|updatePortsFromChoices