Hauptinhalt

findByType

R2026b

Find indices of elements matching specified SysML v2 type

Since R2026b

    Description

    idx = findByType(coll,typeName) returns the indices of the elements in coll whose class is exactly the value of typeName. Specify typeName as a fully qualified class name, such as "sysml.PartDefinition". Use the returned indices for parenthesis indexing into the collection, or combine them with indices from other searches.

    example

    Examples

    collapse all

    Find the positions of part definitions and part usages in a collection, combine them, and index into the collection once.

    Get all elements from the workspace, and find the positions of the part definitions.

    allElements = myFullWorkspace.getElements;
    idx = findByType(allElements,"sysml.PartDefinition")
    idx =
    
         5     9    13

    Combine the positions of part definitions and part usages. Then, index into the collection and list the element names.

    idx = sort([findByType(allElements,"sysml.PartDefinition") ...
                findByType(allElements,"sysml.PartUsage")]);
    defsAndParts = allElements(idx);
    [defsAndParts.declaredName]
    ans =
    
      1×4 string array
    
        "subArch"    "A"    "myTopArch"    "myArch"

    Count the elements of a type without creating a new collection.

    numel(findByType(allElements,"sysml.OwningMembership"))
    ans =
    
         4

    Input Arguments

    collapse all

    Collection, specified as a sysml.Collection object.

    Element class name to match, specified as a string scalar or character vector. Use the fully qualified class name, such as "sysml.PartDefinition" or "sysml.Package". Matching is exact: specifying a superclass, such as "sysml.Definition", does not match its subclasses.

    Data Types: string | char

    Output Arguments

    collapse all

    Indices of matching elements, returned as a vector of positive integers with the same orientation as coll. For a row collection, which is the default, idx is a row vector. For a column collection, idx is a column vector. Each value is the position of a matching element in coll. If no elements match, idx is empty.

    Data Types: double

    More About

    collapse all

    Version History

    Introduced in R2026b