Main Content

Simulink.VariantUtils.convertToVariantSubsystem

Class: Simulink.VariantUtils
Namespace: Simulink

Convert Subsystem, Model, or Configurable Subsystem block to Variant Subsystem block

Since R2023b

Description

variant_subsystem = Simulink.VariantUtils.convertToVariantSubsystem(blockPathOrHandle) converts a Subsystem block, Model block, or Configurable Subsystem block to a Variant Subsystem block. A Variant Subsystem can contain a combination of Subsystem blocks, Model blocks, or Subsystem Reference blocks as choices.

example

variant_subsystem = Simulink.VariantUtils.convertToVariantSubsystem(blockPathOrHandle, options) converts a Subsystem block, Model block, or Configurable Subsystem block to a Variant Subsystem block with the block parameters specified as options.

example

Input Arguments

expand all

The Subsystem, Model, or Configurable Subsystem block to convert to a Variant Subsystem block, specified as a block path or handle. Specify a block path as a character vector and a block handle as a scalar.

Example: 'mdlVar1/VariantModelBlock1'

Block parameters of the Variant Subsystem block. The valid values for options are :

Values of options

optionsValue
VariantControlModelabel or expression
VariantControlBoolean expression or string
VariantActivationTimeupdate diagram,update diagram analyze all choices,code compile, startup,inherit from Simulink.VariantControl,runtime
AllowZeroVariantControlson, off

Example: Simulink.VariantUtils.convertToVariantSubsystem(block_handle,"VariantControlMode", 'expression', 'VariantControl', 'V==1', 'VariantActivationTime', 'update diagram', 'AllowZeroVariantControls', 'on')

Output Arguments

expand all

The block handle of the Variant Subsystem block created by the conversion, returned as a double.

Examples

expand all

Convert the Subsystem block Controller in the f14 model to a Variant Subsystem block.

open_system('f14');
Simulink.VariantUtils.convertToVariantSubsystem('f14/Controller');

Convert the Subsystem block Controller in the f14 model model to a Variant Subsystem block in expression mode with control expression as V==1, and the variant activation time as update diagram and allow zero variant control turned on.

open_system('f14');
Simulink.VariantUtils.convertToVariantSubsystem('f14/Controller', "VariantControlMode", 'expression', 'VariantControl', 'V==1', 'VariantActivationTime', 'update diagram', 'AllowZeroVariantControls', 'on');

Convert the Model block CounterA in the sldemo_mdlref_basic model to a Variant Subsystem block.

open_system('sldemo_mdlref_basic');
Simulink.VariantUtils.convertToVariantSubsystem('sldemo_mdlref_basic/CounterA');

You can convert a Configurable Subsystem block to a Variant Subsystem block using the convertToVariantSubsystem method. See Convert Configurable Subsystem to Variant Subsystem.

Limitations

The convertToVariantSubsystem method does not support Subsystem blocks in a Simscape™ model that has the Editing Mode configuration parameter set to Restricted.

Alternatives

Simulink Editor

In the Simulink® Editor, right-click the Subsystem or Model block and select Subsystems & Model Reference > Convert to > Variant Subsystem.

Version History

Introduced in R2023b

expand all