How to change active variant choice inside a protected model?

I have a library in Simulink that contains a protected model inside it. The protected model contains a variant subsystem. Is there a way to change the active variant choice of the variant subsystem inside the protected model?

 Accepted Answer

Yes, the active variant choice inside a protected model can be controlled using an 'expression' 'Variant control mode' in the variant subsystem and defining a control variable in the MATLAB workspace. Here are the steps in more detail (example model attached):
  1. Set the 'Variant control mode' to 'expression' and 'Variant activation time' to 'startup'. Define the variant control expressions for the different variants. In the example model attached, the control variable is called 'test'. test == 10 activates variant A and test == 20 activates variant B.
  2. Now protect the Simulink model containing the variant.
  3. Finally, create the variable 'test' as a Simulink.Parameter with value 10 and and 'Exported Global' storage class.
test = Simulink.Parameter(10);
test.CoderInfo.StorageClass = 'ExportedGlobal';
Simulate the protected model and observe that variant A is activated (output == 1).
Change the value of 'test' to 20 and simulate the model. Observe that variant B is activated (output == 2).
test.Value = 20;
For more details on tuning parameters inside a protected model, please refer to this MATLAB Answers thread: How do I create a Protected Model with tunable parameters? - MATLAB Answers - MATLAB Central.
This documentation also provides more details on simulating a protected model with 'startup' activation time: Simulate a Protected Model with Code Compile or Startup Activation Time.

More Answers (0)

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!