The ability to use Structs as Variant Control Objects has been added in MATLAB R2018a.
In MATLAB R2017b and earlier, you will observe the following error message:
'myStruct' is not allowed as the left-hand side of 'myStruct.value'
in variant condition expression 'myStruct.value==1' used by block
'myModel/Controller'. Only enumerated type names are allowed.
In MATLAB R2017b and earlier, it is possible to use Struct to create a Variant Control Object, but there is a limitation in using the Variant Struct to perform Variant Control with Model Reference. However, there is a workaround for better organizing the Variants :
VariantName = 1 ;
Variant.a.varControl= 'Simulink.Variant( ''VariantName == 1'' ) ';
Variant.a.Name = 'a';
Variant.b.varControl= 'Simulink.Variant( ''VariantName == 2'' )' ;
Variant.b.Name = 'b';
eval([Variant.a.Name ' = ' Variant.a.varControl]);
eval([Variant.b.Name ' = ' Variant.b.varControl]);
The "eval" statement can be put into a function and called after each Variant is set.
Best Answer