主要内容

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

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 135 115]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 209.0400
    SimulinkModelHandle: 149.2595
                   UUID: '9b1a2203-3a02-4745-9ae6-067b94f4f9fa'
            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 170 120]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 151.0059
    SimulinkModelHandle: 149.2595
                   UUID: '522049ec-4f5b-472d-8e5f-a086cdb97e9f'
            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", EmptyChoice="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 135 115]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 209.0583
    SimulinkModelHandle: 149.3112
                   UUID: '44f6057a-272f-4fe7-808e-f773af52ffb8'
            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 170 120]
                  Model: [1×1 systemcomposer.arch.Model]
         SimulinkHandle: 151.0582
    SimulinkModelHandle: 149.3112
                   UUID: 'c545474e-c5ab-41d9-8532-aa75a87da6e1'
            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

  • off - 当没有有效的变体选择项时,System Composer™ 会引发错误。

  • on - System Composer 在变体选择项表中添加了一个不可修改的变体选择项条目,其值设置为 (default)。该条目在 Variant Component 模块中未作为可见的变体选择项显示。在仿真过程中,如果没有任何变体选择项处于活动状态,System Composer 会断开 Variant Component 模块的变体选择项,并将变体区域从模型中移除。Variant Component 模块中未启用的输出端口输出零。

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

依赖项

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

输出参量

全部折叠

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

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

数据类型: char

详细信息

全部折叠

版本历史记录

在 R2019a 中推出

全部展开