Transform Model to Variant System
You can use the Model Transformer tool to improve model componentization by replacing qualifying modeling patterns with Variant Source and Variant Subsystem, Variant Model, Variant Assembly Subsystem blocks. The Model Transformer reports the qualifying modeling patterns. You choose which modeling patterns the tool replaces with a Variant Source block or Variant Subsystem block.
The Model Transformer can perform these transformations:
If an If block connects to one or more If Action Subsystems and each one has one outport, replace this modeling pattern with a subsystem and a Variant Source block.
If an If block connects to an If Action Subsystem that does not have an outport or has two or more outports, replace this modeling pattern with a Variant Subsystem block.
If a Switch Case block connects to one or more Switch Case Action Subsystems and each one has one outport, replace this modeling pattern with a subsystem and a Variant Source block.
If a Switch Case block connects to a Switch Case Action Subsystem that does not have an outport or has two or more outports, replace this modeling pattern with a Variant Subsystem block.
Replace a Switch block with a Variant Source block.
Replace a Multiport Switch block that has two or more data ports with a Variant Source block.
For the Model Transformer tool to perform the transformation, the control input to Multiport Switch or Switch blocks and the inputs to If or Switch Case blocks must be either of the following:
A Constant block in which the Constant value parameter is a
Simulink.Parameterobject of scalar type.
Constant blocks in which the Constant value parameters are
Simulink.Parameterobjects of scalar type and some other combination of blocks that form a supported MATLAB expression. The MATLAB expressions in Types of Operators in Variant Blocks for Different Activation Times are supported except for bitwise operations.
This example shows how to use the Model Transformer to transform a model into a
variant system. The example uses the model
model has three Switch blocks. The control input to these
Switch blocks is the
cond. The Model Transformer dialog box and this example refer to
cond as a system constant.
Open the model. In the Command Window, type:
Switch1Block Parameters dialog box. Change the Threshold parameter to
0. The Threshold parameter must be an integer because after the variant transformation it is part of the condition expression in the Variant Source block.
Repeat step 2 for the Switch blocks
Save the model to your working folder.
Perform Variant Transform on Example Model
In the Apps tab, Open the Model Transformer by selecting Model Transformer. Or, in the Command Window, type:
Select the check Replace Modeling Patterns with Variant Blocks.
In the Specify system constant cell array field, you can specify a cell array of character vectors consisting of
Simulink.Parameters. The base workspace must contain their definitions.
In the Prefix of transformed model name field, specify a prefix for the model name. If you do not specify a prefix, the default is
Select Run This Check. The Model Transformer lists system constants and blocks that qualify to be part of condition expressions in Variant Source or Variant Subsystem blocks. For the Model Transformer to list a system constant, it must be a
Simulink.Parameterobject of scalar type. For this example,
Condqualifies to part of a condition expression.
If you do not want one of the transformations to occur, you can clear the check box next to it.
Select Refactor Model. The Model Transformer provides a hyperlink to the transformed model and hyperlinks to the corresponding blocks in the original model and the transformed model.
The transformed model or models are in the folder that has the prefix
m2mplus the original model name. For this example, the folder name is
In the original model
ex_model_transform, right-click one of the Switch blocks. In the menu, select Model Transformer > Traceability to Transformed Block. In the transformed model
gen0_ex_model_transform, the corresponding Variant Source block is highlighted.
In the transformed model
gen0_ex_model_transform, right-click one of the Switch blocks. In the menu, select Model Transformer > Traceability to Original Block. In the original model
ex_model_transform, the corresponding Switch block is highlighted.
Model Transformation Limitations
The Model Transformer tool has these limitations:
In order to run the Model Transformer on a model, you must be able to simulate the model.
If an If Action Subsystem block drives a Merge block, and the Merge block has another inport that is either unconnected or driven by another conditional subsystem, the Model Transformer does not add a Variant Source block. This modeling pattern produces a warning and an excluded candidate message.
The Model Transformer cannot perform a variant transformation for every modeling pattern. This list contains some exceptions:
The model contains a Model block that references a protected model.
A model contains a Variant Source block with the Variant activation time parameter set to
After you run one or more tasks, you cannot rerun the tasks because the Run this Check and Run All buttons are deactivated. If you want to rerun a task, reset the Model Transformer by right-clicking Model Transformer and selecting
Do not change a model in the middle of a transformation. If you want to change the model, close the Model Transformer, modify the model, and then reopen the Model Transformer.
For the hyperlinks in the Model Transformer to work, you must have the model to which the links point to open.