This example shows you how to simulate a protected model in the
code compile and
startup variant activation times.
Open the model
slexVariantMdlRefCondProp.slx. The model contains two Model blocks,
sub2. The variant condition
V == 1 is propagated to the Model Block
sub1. However, the condition is not propagated to the blocks within
sub1. The blocks within
sub1 implicitly inherit the condition. The Model block
sub2 propagates the
Out variant conditions.
code compileActivation Time
Before you simulate, protect the Model block
sub2. To protect the model reference of
sub2, select the block
sub2 and enter this command in the MATLAB Command Window. For more information on protecting models, see Protect Models to Conceal Contents (Simulink Coder).
When the Variant activation time is set to
code compile, changing the active variant for variant blocks in a protected model is not supported.
Before you simulate the model with
startup activation time, delete the protected model.
Set the Variant activation time of the Variant Sink block in the Model Block
startup. Change the variant control to
'W' and change the storage class specification of
W = copy(V); W.CoderInfo.StorageClass = 'ExportedGlobal';
Protect the model and change the active variant to simulate the model.
Simulink.ModelReference.protect(gcb); W.Value = int32(3);
W == 3 is propagated to the