Main Content

sysml.Collection

R2026b

Filter, index, and inspect SysML v2 elements

Since R2026b

    Description

    A sysml.Collection object is a container for sysml.Element elements. systemcomposer.sysml.Workspace methods such as getElements, getRootElements, and getElementsByTypeAndName return a collection object. Multi-valued SysML® v2 element properties, such as ownedMember and ownedFeature, also return collections. You can index into a collection with parentheses, filter by SysML v2 type by using dot notation, access properties across all elements, and iterate over elements in a for loop. Collections are row-oriented by default.

    Properties

    expand all

    Collection Metadata

    This property is read-only.

    Number of elements in the collection, represented as a nonnegative integer.

    Data Types: double

    This property is read-only.

    Class name of each element in the collection, represented as a string array of the same size as the collection. Each entry is a fully qualified class name, such as "sysml.PartDefinition", in collection order. To get the distinct types, use unique(coll.Types). This property returns the same value as the getObjectTypes function.

    Data Types: string

    This property is read-only.

    Number of elements of each class in the collection, represented as a containers.Map object. Each key is a fully qualified class name, such as 'sysml.PartDefinition', and each value is the number of elements of that class. For example, coll.TypeCounts("sysml.PartDefinition") returns the number of part definitions. This property returns the same value as the getTypeCounts function.

    Object Functions

    expand all

    filterByTypeFilter collection to elements of specified SysML v2 type
    findByTypeFind indices of elements matching specified SysML v2 type
    getObjectTypesGet class name of each element in collection
    getTypeCountsCount elements of each type in collection
    toCellConvert collection to cell array of SysML v2 elements
    numelNumber of array elements
    lengthLength of largest array dimension
    sizeArray size
    ndimsNumber of array dimensions
    isemptyDetermine whether array is empty
    isscalarDetermine whether input is scalar
    isrowDetermine if input is row vector
    iscolumnDetermine if input is column vector
    transposeTranspose vector or matrix
    ctransposeComplex conjugate transpose
    catConcatenate arrays
    vertcatConcatenate arrays vertically
    horzcatConcatenate arrays horizontally

    Examples

    collapse all

    Get all elements from a workspace, inspect the collection metadata, filter by SysML v2 type, broadcast property access, index into a filtered collection, and iterate over elements.

    Get all elements from the workspace. The result is a sysml.Collection object.

    allElements = myFullWorkspace.getElements
    allElements =
    
      1×13 Collection array with no properties.

    Inspect the collection metadata. The Types property has one class name for each element, so use unique to list the distinct types.

    allElements.Count
    ans =
    
        13
    unique(allElements.Types)'
    ans =
    
      8×1 string array
    
        "sysml.FeatureMembership"
        "sysml.FeatureTyping"
        "sysml.Namespace"
        "sysml.OwningMembership"
        "sysml.Package"
        "sysml.PartDefinition"
        "sysml.PartUsage"
        "sysml.Subclassification"
    counts = allElements.TypeCounts;
    counts("sysml.PartDefinition")
    ans =
    
         3

    Filter to PartDefinition elements by using dot type filtering. Then, broadcast declaredName across the filtered collection. Enclose the broadcast in square brackets to collect the value from every element.

    partDefs = allElements.PartDefinitions
    partDefs =
    
      1×3 Collection array with no properties.
    names = [partDefs.declaredName]
    names =
    
      1×3 string array
    
        "subArch"    "myTopArch"    "myArch"

    Index into the filtered collection to get one element by name. Then, navigate from that element to its features and iterate over them.

    topArch = partDefs(names == "myTopArch");
    features = topArch.ownedFeature;
    for elem = features
        fprintf("%s: %s\n",elem.meta,elem.declaredName)
    end
    PartUsage: A

    More About

    expand all

    Version History

    Introduced in R2026b