You can use the Model Transformer tool to improve model componentization by replacing qualifying modeling patterns with Variant Source and Variant Subsystem, Variant Model 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.Parameter
object
of scalar type.
Constant blocks in which the Constant
value parameters are Simulink.Parameter
objects
of scalar type and some other combination of blocks that form a supported MATLAB
expression. The MATLAB expressions in Operators and Operands in Variant Condition Expressions 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 rtwdemo_controlflow_opt
.
This model has three Switch blocks. The control input to these
Switch blocks is the Simulink.Parameter
cond
. The Model Transformer dialog box and this example refer to
cond
as a system constant.
Open the model. In the Command Window, type
rtwdemo_controlflow_opt
.
Open the Switch1
Block 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
Switch1
, Switch2
, and
Switch3
.
Save the model to your working folder.
In the Apps tab, Open the Model Transformer by selecting
Model Transformer. Or, in the Command Window, type:
mdltransformer('rtwdemo_controlflow_opt')
Select the check Transform the model to variant system.
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
gen0
.
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.Parameter
object of scalar type. For this example,
Cond
qualifies 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
m2m
plus the original model name. For this example, the
folder name is m2m_rtwdemo_controlflow_opt
.
In the original model rtwdemo_controlflow_opt
, right-click
one of the Switch blocks. In the menu, select Model Transformer > Traceability to Transformed Block. In the transformed model
gen0_rtwdemo_controlflow_opt
, the corresponding
Variant Source block is highlighted.
In the transformed model gen0_rtwdemo_controlflow_opt
,
right-click one of the Switch blocks. In the menu, select Model Transformer > Traceability to Original Block. In the original model rtwdemo_controlflow_opt
,
the corresponding Switch block is highlighted.
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 protected model reference block.
A model contains a Variant Source block with the
Variant activation
time parameter set to
update diagram
.
After you run one or more tasks, you cannot rerun the tasks because the
Run this Task and Run
All buttons are deactivated. If you want
to rerun a task, reset the Model Transformer by right-clicking
Model Transformer and selecting
Reset
.
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.