主要内容

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

findElementsOfType

查找特定类型的所有元素

自 R2023a 起

    说明

    elements = findElementsOfType(containerObj,kind) 查找 kind 类型的所有元素 elements

    示例

    elements = findElementsOfType(containerObj,kind,Name=Value) 查找一个类型的所有元素,并带有由一个或多个名称-值参量指定的附加选项。

    示例

    全部折叠

    使用 System Composer™ 查询命名空间中的函数过滤模型中的元素。

    导入包含所有 System Composer 查询的命名空间。

    import systemcomposer.query.*

    加载模型和配置文件。

    sysModel = systemcomposer.loadModel("mBasicModel");
    basicProfile = systemcomposer.loadProfile("mProfile");

    查找模型中的所有组件。

    allComps = findElementsOfType(sysModel,"Component")
    allComps=1×10 Component array with properties:
        IsAdapterComponent
        Architecture
        ReferenceName
        Name
        Parent
        Ports
        OwnedPorts
        OwnedArchitecture
        Parameters
        Position
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    查找模型中的所有端口。

    allPorts = findElementsOfType(sysModel,"Port")
    allPorts=1×19 ComponentPort array with properties:
        Parent
        ArchitecturePort
        Name
        Direction
        InterfaceName
        Interface
        InheritsInterface
        Connectors
        Connected
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    查找模型中的所有构造型。

    allStereotypes = findElementsOfType(basicProfile,"Stereotype")
    allStereotypes=1×10 Stereotype array with properties:
        Name
        Description
        Parent
        AppliesTo
        Abstract
        Icon
        ComponentHeaderColor
        ConnectorLineColor
        ConnectorLineStyle
        FullyQualifiedName
        Profile
        OwnedProperties
        Properties
    
    

    查找模型中的所有接口。

    allInterfaces = findElementsOfType(sysModel,"Interface")
    allInterfaces=1×7 heterogeneous Interface (ValueType, PhysicalInterface, DataInterface) array with properties:
        UUID
        ExternalUID
    
    

    查找模型中名称包含 "c1" 的组件。

    nameComponents = findElementsWithProperty(sysModel,"Component","Name","c1","contains")
    nameComponents=1×2 Component array with properties:
        IsAdapterComponent
        Architecture
        ReferenceName
        Name
        Parent
        Ports
        OwnedPorts
        OwnedArchitecture
        Parameters
        Position
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    查找配置文件中名称包含 "BasePort" 的所有构造型。

    basePortStereotype = findElementsWithProperty(basicProfile,"Stereotype","Name","BasePort","eq")
    basePortStereotype = 
      Stereotype with properties:
    
                        Name: 'BasePort'
                 Description: ''
                      Parent: [0×0 systemcomposer.profile.Stereotype]
                   AppliesTo: 'Port'
                    Abstract: 1
                        Icon: ''
        ComponentHeaderColor: [210 210 210]
          ConnectorLineColor: [168 168 168]
          ConnectorLineStyle: 'Default'
          FullyQualifiedName: 'mProfile.BasePort'
                     Profile: [1×1 systemcomposer.profile.Profile]
             OwnedProperties: [0×0 systemcomposer.profile.Property]
                  Properties: [0×0 systemcomposer.profile.Property]
    
    

    使用 "BasePort" 构造型查找模型中的所有组件。

    basePorts = findElementsWithStereotype(sysModel,"Port",basePortStereotype)
    basePorts=1×18 ComponentPort array with properties:
        Parent
        ArchitecturePort
        Name
        Direction
        InterfaceName
        Interface
        InheritsInterface
        Connectors
        Connected
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    使用前两个找到的接口查找所有元素。

    portsUsingInterfaces = findElementsWithInterface(sysModel,"Port",[allInterfaces(1) allInterfaces(2)])
    portsUsingInterfaces=1×2 ComponentPort array with properties:
        Parent
        ArchitecturePort
        Name
        Direction
        InterfaceName
        Interface
        InheritsInterface
        Connectors
        Connected
        Model
        SimulinkHandle
        SimulinkModelHandle
        UUID
        ExternalUID
    
    

    输入参数

    全部折叠

    元素类型,指定为这些选项之一:

    • "Component"

    • "Port"

    • "Connector"

    • "Interface"

    • "InterfaceElement"

    • "Stereotype"

    数据类型: string

    名称-值参数

    全部折叠

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

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

    示例: allComps = systemcomposer.query.findElementsOfType(sysModel,"Component",NegateResult=true,IncludeReferences=false)

    是否否定查询结果,指定为 1 (true) 或 0 (false)。

    数据类型: logical

    搜索引用架构的选项,指定为 1 (true) 或 0 (false)。

    数据类型: logical

    输出参量

    全部折叠

    详细信息

    全部折叠

    版本历史记录

    在 R2023a 中推出