주요 콘텐츠

getTypeCounts

R2026b

Count elements of each type in collection

Since R2026b

    Description

    counts = getTypeCounts(coll) returns a containers.Map object. The object keys are the fully qualified class names of the elements in coll, and its values are the number of elements of each class. getTypeCounts(coll) returns the same value as the TypeCounts property of coll.

    example

    Examples

    collapse all

    Count the elements of each type in a collection before you filter it.

    Get all elements from the workspace and count them by type. The Count property of the map is the number of distinct types.

    allElements = myFullWorkspace.getElements;
    counts = getTypeCounts(allElements)
    counts =
    
      Map with properties:
    
            Count: 8
          KeyType: char
        ValueType: double

    Look up the number of part definitions.

    counts("sysml.PartDefinition")
    ans =
    
         3

    List every type with its count.

    typeNames = keys(counts);
    for k = 1:numel(typeNames)
        fprintf("%s: %d\n",typeNames{k},counts(typeNames{k}))
    end
    sysml.FeatureMembership: 1
    sysml.FeatureTyping: 1
    sysml.Namespace: 1
    sysml.OwningMembership: 4
    sysml.Package: 1
    sysml.PartDefinition: 3
    sysml.PartUsage: 1
    sysml.Subclassification: 1

    Input Arguments

    collapse all

    Collection, specified as a sysml.Collection object.

    Output Arguments

    collapse all

    Number of elements of each class, returned as a containers.Map object. The keys are fully qualified class names, specified as character vectors, and the values are counts, specified as double values. For an empty collection, the map has no keys.

    More About

    collapse all

    Version History

    Introduced in R2026b