When to use Enumerations in Variant control expressions?

1 view (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 26 Sep 2022
The variant choices you select, determine which components of a Simulink model get activated or deactivated.
You can create a Variant control (e.g: engine ) and associate it with an expression say: "engine == 1", "engine == 2", and "engine == 3". The Variant control expressions get evaluated and decide the active choice of a Variant block.
In a likely scenario, there could be many variant blocks in your model, and typing and changing expressions like "engine == 1" may lead to less readability. To associate your variant controls with more meaningful names, use Enumerations.
Exploring  "Enumerations" in expression mode can help you with self-explanatory
.
Instead of " engine == 1", you can have "engine == Engine.TURBO"
To get started, please consider exploring some examples demonstrating Simulink Variant capabilities.
Using Enumeration in Variant control expression has advantage over using label mode, as they can be used for Variant parameters too. If you want to learn more on how to create parameters that have multiple values, please refer to the documentation:
Variant Parameters require association with a variant condition expression and enumerations come in handy to use self-explanatory names for Variant controls. Please refer to this
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!