Update February 2019
To convert your existing models, you can use Simulink.VariantManager.convertToVariant or run the Upgrade Advisor check Identify Variant Model blocks and convert those to Variant Subsystem containing Model block choices.
By Guy Rouleau
In a previous post, Seth introduced the concept of Model Reference and the advantages it brings for dealing with large models. Since MATLAB R2009b, Model Reference Variants make it easy to reconfigure your model for different design variants.
What are Model Reference Variants?
In Model-Based Design, you want your design process to be centered around a single model, however, design variations may require different implementations for different purposes. For example, imagine that you want to model a vehicle that has three possible engine configurations:
- 4 cylinder gas
- 6 cylinder gas
- 4 cylinder diesel
Using model reference variants, you could implement each engine model as a separate reference model and then switch between them based on the value of some variables in your workspace.
How does that work?
To begin, drag a Model block from the Simulink Library Browser and double-click on it. Instead of entering the name of one model you want to reference, click the Enable Variants button.
The Model Reference dialog window will change to enable you to define Variant choices
For each variant specified in the Model Reference block, create a Simulink.Variant object. The Simulink.Variant object specifies a Boolean expression called a variant condition. When running the model, the Model Reference block evaluates the variant conditions of the Simulink.Variant objects to determine which model is active.
For the example described above, define variants for all three options:
Eng4cGAS = Simulink.Variant('(cyl==4) && (fuel==1)'); Eng6cGAS = Simulink.Variant('(cyl==6) && (fuel==1)'); Eng4cDIESEL = Simulink.Variant('(cyl==4) && (fuel==2)');
Define variables in the base workspace needed by the variant conditions:
fuel = 1; cyl = 4;
In the parent model, the model block displays the name of the active model and an additional icon .
Now it’s your turn!
Are you using the model reference variants? Leave a comment here.
UPDATE - 10/15/2013: New capabilities starting in R2013b.
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.