Main Content

Simulink.VariantManager.convertToVariant

Class: Simulink.VariantManager
Package: Simulink

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

Description

Note

This method requires Variant Manager for Simulink®.

example

variant_subsystem = Simulink.VariantManager.convertToVariant(blockPathOrHandle) converts a Subsystem block, Model block, or Variant Model block to a Variant Subsystem block. A Variant Subsystem can contain Subsystem blocks, Model blocks, or both as choices.

Note

Future releases will no longer support using a Model block to contain model variants. You can use the convertToVariant method to convert model variants so that Model blocks are contained in a Variant Subsystem. Use of a Variant Subsystem block provides these advantages:

  • Allows you to mix Model and Subsystem blocks as variant choices

  • Supports flexible I/O, so that all variants do not need to have the same number of input and output ports

For an example of a model that uses a Variant Subsystem block as a container for variant models, see Model Reference Variants.

Input Arguments

expand all

The Subsystem or Model 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'

Output Arguments

expand all

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

Examples

expand all

Consider this model with a Subsystem block.

You can convert this Subsystem block to a Variant Subsystem block using the convertToVariant method.

Similarly you can convert a Variant Model block to a Variant Subsystem block.

If there are inconsistencies in the port name or port number in models referenced by Variant Model block, Simulink corrects these inconsistencies while converting the Variant Model block to a Variant Subsystem block.

Consider this model with a Variant Model block having different port names.

When you convert this Variant Model block to a Variant Subsystem block, the inconsistencies are corrected automatically.

Limitations

The convertToVariant method does not support these scenarios:

  • The Subsystem block is in a Simscape™ model that has Editing Mode set to Restricted.

  • The Variant Model block has a mix of control ports or there is a name mismatch in control port types.

  • The Variant Model block has control ports with different port numbers and name mapping.

Alternatives

Simulink Editor

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

Upgrade Advisor Check

To convert a Variant Model block to a Variant Subsystem block, you can use the Upgrade Advisor check Identify Variant Model blocks and convert those to Variant Subsystem containing Model block choices. This check provides a Fix button to convert Variant Model blocks to Variant Subsystem blocks. For more information on using Upgrade Advisor check to convert a Variant Model block to a Variant Subsystem block, see Upgrade Advisor Checks.

Version History

Introduced in R2017b