Is there a way to define Variant Control Objects as Struct in Simulink?

4 views (last 30 days)
I need to pass to a Simulink Model Reference blocks (defined with Variants) an argument
defined as a Struct, and use this Struct to perform Variant Control. I want to do this because I have too many Variants in the Workspace and I want to better organize my Variants. Is it possible to do this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 Nov 2019
Edited: MathWorks Support Team on 25 Nov 2019
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.

More Answers (0)

Categories

Find more on Component-Based Modeling in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!