主要内容

toCell

R2026b

Convert collection to cell array of SysML v2 elements

Since R2026b

    Description

    elements = toCell(coll) converts the sysml.Collection object coll to a cell array. Each cell contains one sysml.Element object. The cell array has the same size and element order as the collection.

    example

    Examples

    collapse all

    Convert a collection to a cell array, and then use cellfun to build a label from two properties of each element.

    Get the part definitions from the workspace and convert them to a cell array.

    allElements = myFullWorkspace.getElements;
    partDefs = allElements.PartDefinitions;
    elements = toCell(partDefs)
    elements =
    
      1×3 cell array
    
        {1×1 sysml.PartDefinition}    {1×1 sysml.PartDefinition}    {1×1 sysml.PartDefinition}

    Build a label for each element from its name and type.

    labels = cellfun(@(e) sprintf("%s (%s)",e.declaredName,e.meta),elements)
    labels =
    
      1×3 string array
    
        "subArch (PartDefinition)"    "myTopArch (PartDefinition)"    "myArch (PartDefinition)"

    Input Arguments

    collapse all

    Collection, specified as a sysml.Collection object.

    Output Arguments

    collapse all

    Elements from the collection, returned as a cell array the same size as coll. Each cell contains one sysml.Element object. For an empty collection, elements is a 1-by-0 cell array.

    Data Types: cell

    More About

    collapse all

    Version History

    Introduced in R2026b