Is there a way to define Variant Control Objects as Struct in Simulink?
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 25 Oct 2013
Modifié(e) : MathWorks Support Team
le 25 Nov 2019
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?
Réponse acceptée
MathWorks Support Team
le 26 Nov 2019
Modifié(e) : MathWorks Support Team
le 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Blocks dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!