Main Content

makeVariant

Convert component to variant choice

Description

[variantComp,choices] = makeVariant(component) converts the component component to a variant choice component and returns the parent Variant Component block object variantComp and available variant choice components choices.

example

[variantComp,choices] = makeVariant(component,Name=Value) converts the component component to a variant choice component with additional options and returns the parent Variant Component block object variantComp and available variant choice components choices.

example

Examples

collapse all

Create a top-level architecture model.

modelName = "archModel";
arch = systemcomposer.createModel(modelName);
systemcomposer.openModel(modelName);
rootArch = get(arch,"Architecture");

Create a new component.

newComponent = addComponent(rootArch,"Component");

Add ports to the component.

inPort = addPort(newComponent.Architecture,"testSig","in");
outPort = addPort(newComponent.Architecture,"testSig","out");

Make the component into a variant component.

[variantComp,choices] = makeVariant(newComponent)
variantComp = 
  VariantComponent with properties:

           Architecture: [1×1 systemcomposer.arch.Architecture]
                   Name: 'Component'
                 Parent: [1×1 systemcomposer.arch.Architecture]
                  Ports: [1×2 systemcomposer.arch.ComponentPort]
             OwnedPorts: [1×2 systemcomposer.arch.ComponentPort]
      OwnedArchitecture: [1×1 systemcomposer.arch.Architecture]
             Parameters: [0×0 systemcomposer.arch.Parameter]
               Position: [15 15 65 83]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 213.0017
    SimulinkModelHandle: 153.0015
                   UUID: 'f6c60b77-9192-4c8a-b9cc-6682fcf50ef2'
            ExternalUID: ''

choices = 
  Component with properties:

     IsAdapterComponent: 0
           Architecture: [1×1 systemcomposer.arch.Architecture]
                   Name: 'Component'
                 Parent: [1×1 systemcomposer.arch.Architecture]
                  Ports: [1×2 systemcomposer.arch.ComponentPort]
             OwnedPorts: [1×2 systemcomposer.arch.ComponentPort]
      OwnedArchitecture: [1×1 systemcomposer.arch.Architecture]
             Parameters: [0×0 systemcomposer.arch.Parameter]
               Position: [50 20 100 80]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 155.0024
    SimulinkModelHandle: 153.0015
                   UUID: 'aaefc71c-1f04-46f6-aa31-3f0873986048'
            ExternalUID: ''

Create a top-level architecture model.

modelName = "archModel";
arch = systemcomposer.createModel(modelName);
systemcomposer.openModel(modelName);
rootArch = get(arch,"Architecture");

Create a new component.

newComponent = addComponent(rootArch,"Component");

Add ports to the component.

inPort = addPort(newComponent.Architecture,"testSig","in");
outPort = addPort(newComponent.Architecture,"testSig","out");

Make the component into a variant component in expression mode.

[variantComp,choices] = makeVariant(newComponent, VariantControl = "V==1", VariantActivationTime = "update diagram", AllowZeroVariantControls="on")
variantComp = 
  VariantComponent with properties:

           Architecture: [1×0 systemcomposer.arch.Architecture]
                   Name: 'Component'
                 Parent: [1×1 systemcomposer.arch.Architecture]
                  Ports: [1×2 systemcomposer.arch.ComponentPort]
             OwnedPorts: [1×2 systemcomposer.arch.ComponentPort]
      OwnedArchitecture: [1×1 systemcomposer.arch.Architecture]
             Parameters: [0×0 systemcomposer.arch.Parameter]
               Position: [15 15 65 83]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 213.0018
    SimulinkModelHandle: 153.0016
                   UUID: '115db9d3-e264-496a-8016-15c01ec4c150'
            ExternalUID: ''

choices = 
  Component with properties:

     IsAdapterComponent: 0
           Architecture: [1×1 systemcomposer.arch.Architecture]
                   Name: 'Component'
                 Parent: [1×1 systemcomposer.arch.Architecture]
                  Ports: [1×2 systemcomposer.arch.ComponentPort]
             OwnedPorts: [1×2 systemcomposer.arch.ComponentPort]
      OwnedArchitecture: [1×1 systemcomposer.arch.Architecture]
             Parameters: [0×0 systemcomposer.arch.Parameter]
               Position: [50 20 100 80]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 155.0026
    SimulinkModelHandle: 153.0016
                   UUID: 'ae99af05-bf06-4e1b-8779-b95c76330a1b'
            ExternalUID: ''

Input Arguments

collapse all

Component to be converted to variant choice component, specified as a systemcomposer.arch.Component object.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: [variantComp,choices] = makeVariant(newComponent,Name="NewVariantComponent",Label="NewVariantChoice",Choices=["NewVariantChoiceA","NewVariantChoiceB","NewVariantChoiceC"],ChoiceLabels=["Choice A","Choice B","Choice C"])

Name of variant component, specified as a character vector or string.

Example: [variantComp,choices] = makeVariant(newComponent,Name="NewVariantComponent")

Data Types: char | string

Label of variant choice from converted component, specified as a character vector or string.

Example: [variantComp,choices] = makeVariant(newComponent,Name="NewVariantComponent",Label="NewVariantChoice")

Data Types: char | string

Variant choice names, specified as a cell array of character vectors or an array of strings. Additional variant choices are also added to the new variant component, along with the active choice from the converted component.

Example: [variantComp,choices] = makeVariant(newComponent,Choices=["NewVariantChoiceA","NewVariantChoiceB","NewVariantChoiceC"])

Data Types: char | string

Variant choice labels, specified as a cell array of character vectors or an array of strings.

Example: [variantComp,choices] = makeVariant(newComponent,Choices=["NewVariantChoiceA","NewVariantChoiceB","NewVariantChoiceC"],ChoiceLabels=["Choice A","Choice B","Choice C"])

Data Types: char | string

Variant control expression, specified as boolean expression. The active variant choice is determined based on the evaluation of the boolean expression. The variant component created is in expression mode.

Example: [variantComp,choices] = makeVariant(newComponent, VariantControl = ‘V==1’)

Data Types: char | string

Variant activation time, specified as a string or character vector. The active variant choice is determined based on the evaluation of the boolean expression. For a Reference Component with Simulink® behaviour, the variant activation times supported are : update diagram, update diagram analyze all choices, code compile, startup, runtime, and inherit from Simulink.VariantControl.

Example: [variantComp,choices] = makeVariant(newComponent, VariantControl = ‘V==1’,VariantActivationTime = update diagram)

Dependencies

To enable this parameter, you must specify VariantControl.

Data Types: char | string

Allow zero active variant choice option of the Variant Component, specified as off or on.

Example: [variantComp,choices] = makeVariant(newComponent, VariantControl = ‘V==1’, AllowZeroVariantControls=’on’)

Dependencies

To enable this parameter, you must specify VariantControl.

Output Arguments

collapse all

Variant component, returned as a systemcomposer.arch.VariantComponent object.

Variant choices, returned as an array of systemcomposer.arch.Component objects.

Data Types: char

More About

collapse all

Version History

Introduced in R2019a