主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

makeVariant

将组件转换为变体选择项

说明

[variantComp,choices] = makeVariant(component) 将组件 component 转换为变体选择项组件,并返回父 Variant Component 模块对象 variantComp 和可用的变体选择项组件 choices

示例

[variantComp,choices] = makeVariant(component,Name=Value)component 组件转换为带有附加选项的变体选择项组件,并返回父级 Variant Component 模块对象 variantComp 和可用的变体选择项组件 choices

示例

示例

全部折叠

创建顶层架构模型。

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

创建一个新组件。

newComponent = addComponent(rootArch,"Component");

为组件添加端口。

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

将组件变为变体组件。

[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: ''

创建顶层架构模型。

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

创建一个新组件。

newComponent = addComponent(rootArch,"Component");

为组件添加端口。

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

expression 模式下,将组件变为变体组件。

[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: ''

输入参数

全部折叠

要转换为变体选择项组件的组件,指定为 systemcomposer.arch.Component 对象。

名称-值参数

全部折叠

Name1=Value1,...,NameN=ValueN 的形式指定可选参量对组,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。

在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来

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

变体组件的名称,指定为字符向量或字符串。

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

数据类型: char | string

来自转换组件的变体选择项的标签,指定为字符向量或字符串。

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

数据类型: char | string

变体选择项名称,指定为字符向量元胞数组或字符串数组。其他变体选择项也会与转换组件中的活动选择项一起添加到新的变体组件中。

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

数据类型: char | string

变体选择项标签,指定为字符向量元胞数组或字符串数组。

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

数据类型: char | string

变体控制表达式,指定为布尔表达式。活动变体选择项是根据布尔表达式的计算结果确定的。创建的变体组件采用 expression 模式。

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

数据类型: char | string

变体激活时间,指定为字符串或字符向量。活动变体选择项是根据布尔表达式的计算结果确定的。对于具有 Simulink® 行为的 Reference Component,支持的变体激活时间为:update diagramupdate diagram analyze all choicescode compilestartupruntimeinherit from Simulink.VariantControl

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

依赖项

要启用该参数,必须指定 VariantControl

数据类型: char | string

允许变体组件的活动变体选择项选项为零,指定为 offon

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

依赖项

要启用该参数,必须指定 VariantControl

输出参量

全部折叠

变体组件,以 systemcomposer.arch.VariantComponent 对象的形式返回。

变体选择项,以 systemcomposer.arch.Component 对象数组的形式返回。

数据类型: char

详细信息

全部折叠

版本历史记录

在 R2019a 中推出