MATLAB: How to switch between child subsystems of a Variant Subsystem through a pop-up menu or a radio button

buttondowndropdrop downmaskmenupoppopupradiosimulinksubsystemsupvariant

In my Simulink model I have a Variant Subsystem with two (or more) child subsystems. I would like to create a mask from which I can quickly activate the desired variant.

Best Answer

Right-click on the Variant Subsystem, select 'Block Parameters (Subsystem)', and enable 'Override variant conditions and use the following variant'.
Then, please refer to the following steps:
1. Create a mask for the Variant Subsystem (Right click on the Variant Subsystem > Mask > Create Mask...)
2. In the Parameters & Dialog tag, add a Popup (or a Radio button) control, specify a desired prompt message, as well as the name of the variable you will use to switch between variants (e.g., myVar)
3. In the Property editor, in the 'Properties' section, click on 'Type options' and enter the desired options (the options should correspond to the Variant Control names). Then select an initial variant for the field 'Value'.
The variant control names can be found by right-clicking on the Variant Subsystem > Block Parameters (Subsystem), in the 'Variant Control' column.
4. In the Property editor, in the 'Dialog' section, add the following Callback:
>> set_param(gcb,'OverrideUsingVariant',get_param(gcb,'myVar'));
If you wish to activate variants programmatically from MATLAB rather than Simulink canvas from the subsystem mask, please execute the following command:
>> set_param(subsystemName,'OverrideUsingVariant',variantControlName);
For further details, please refer to the attached Simulink model (R2018a).