MATLAB: How to set the variant object of a Variant Subsystem block based on the current value of a mask parameter in Simulink 7.8 (R2011b)

callbackdialogmaskparametersimulinksubsystemvariant

I am using a Variant Subsystem block. I would like to set the variant object based on the current value of a mask parameter.

Best Answer

This can by achieved by using a Dialog callback, which is executed every time a parameter is changed. To access the Dialog callback, right click on the mask --> Edit Mask --> Parameter --> select the parameter of interest. The Dialog callback is in the lower right panel.
To get the current value of the mask parameter, include the following command in the Dialog callback:
currParamVal = get_param('modelName/maskName','parameterName')
To set the variant object, include the following command in the Dialog callback:
set_param('modelName/variantSubsystemName','OverrideUsingVariant','variantName')
Use IF/ELSEIF/ELSE in the Dialog callback to set the variant object based on the parameter value.
Please see the attached model for an example.