Convert Variant Subsystem to Variant Assembly Subsystem
A Variant Assembly Subsystem block enables you to add or remove its variant choices from external sources without modifying the model. The Variant Assembly Subsystem block can contain Model blocks, Subsystem Reference blocks, or both as its variant choices. The choices are maintained in corresponding model or subsystem files that are on the MATLAB® path.
During the conversion, the Variant Assembly Subsystem block:
Validates the current configuration of Variant Subsystem for conversion
Converts all the Subsystem choices (if any) to Subsystem Reference choices with the same name as the block
Constructs a variant choice specifier of the form
{'<file_1>', '<file_2>', …, '<file_N>'}
, wherefile_k
is the model or subsystem file name that contains the choice blocksOverwrites the values of the parameters Name (read-only) and Variant control label with the name of the model or subsystem files
Displays the File and the Path of the newly added variant choices in the Variant Choices table
Convert Variant Subsystem to Variant Assembly Subsystem Through Block Dialog
Open a model containing a Variant Subsystem block.
Set the Variant control mode parameter to
label
in the block dialog.On the Reference tab, click the Convert to Variant Assembly... button.
If the Variant Subsystem block has at least one Subsystem block as its variant choice then a Convert Subsystem choices to Subsystem Reference dialog is displayed. Specify these details in the dialog:
In the Location of new subsystem reference parameter, specify a path to the folder where all the new Subsystem Reference blocks are to be saved in subsystem files. The folder path can be either a relative path to the model that contains the Variant Subsystem block or an absolute path. You can also select a folder from the file system by clicking the Browse folder… button.
By default, the relative folder path is generated with
_subsystem_choices
appended to the Variant Subsystem block name. The absolute path of that folder is displayed in the Absolute path parameter.The List of new subsystem filenames lists the names of the subsystem files that correspond to the newly created Subsystem Reference blocks after the conversion. The names of the subsystem files are the same as the Subsystem blocks to be converted.
To validate the current configuration of the Variant Subsystem block, click Convert. If these validations pass, the Variant Subsystem block is converted to a Variant Assembly Subsystem block:
If the specified folder exists in the file system but not on the MATLAB path, you must resolve the issue by clicking Add to path from the dialog or using the
addpath
function.If the specified folder does not exist in the file system, Simulink® attempts to create the folder by using
mkdir
command and then add it to the MATLAB path.If the specified folder contains a file whose name matches with one of the new subsystem file names, you must determine if you want to replace them.
Convert Variant Subsystem Block to Variant Assembly Subsystem Programmatically
This example explains how to convert the Variant Subsystem block in a Simulink® model to a Variant Assembly Subsystem using the Simulink.VariantManager.convertToVariantAssemblySubsystem
method.
1. Consider the Controller
block in the slexVariantSubsystems
model. The Controller
block is a Variant Subsystem block that is to be converted to a Variant Assembly Subsystem block.
modelName = 'slexVariantSubsystems';
open_system(modelName);
VSS_MODE = 2
vssBlockPath = [modelName, '/Controller'];
2. Set the variant control mode of the Controller
block to label.
set_param(vssBlockPath, 'VariantControlMode', 'label');
3. To convert the Controller
block to a Variant Assembly Subsystem block, use the convertToVariantAssemblySubsystem
method. After the conversion, the Subsystem choices Linear_Controller
and Nonlinear_Controller
are converted to Subsystem Reference blocks with the same name as the Subsystem blocks. The Subsystem Reference blocks are saved in the newly created subsystem files Linear_Controller.slx and Nonlinear_Controller.slx
in your current working folder.
Simulink.VariantManager.convertToVariantAssemblySubsystem(vssBlockPath, pwd);
Limitations
Only the Variant Subsystem block with the Variant control
mode set to label
can be converted to a
Variant Assembly Subsystem block.
See Also
Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files