Main Content

addEnumType

Add enumerated type to Architectural Data section of Simulink data dictionary

Since R2023b

    Description

    enumeratedDataType = addEnumType(archData,enumeratedDataTypeName) adds a Simulink® enumeration enumeratedDataTypeName to archData, the Architectural Data section of a data dictionary.

    example

    enumeratedDataType = addEnumType(archData,enumeratedDataTypeName,EnumTypeDefinition=enumDefn)creates an enumerated data type with the same properties as the Simulink.data.dictionary.EnumTypeDefinition object specified by enumDefn and stores it in the Architectural Data section specified by archData.

    example

    Examples

    collapse all

    To add a Simulink enumeration with a specified name to the data dictionary, use the addEnumType function.

    Create or open a data dictionary.

    dictName = "dataDictionary.sldd";
    archData = Simulink.dictionary.archdata.create(dictName);
    

    Add enumerated data type objects to the Architectural Data section of a data dictionary using the addEnumType function.

    myEnumType1 = addEnumType(archData,"myColor")
    
    myEnumType1 = 
    
      EnumType with properties:
    
                Name: 'myColor'
         Description: ''
        DefaultValue: 'enum1'
         StorageType: 'Native Integer'
           Enumerals: [1×1 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    For more information regarding storing architectural data in a data dictionary, see Store Data in Architectural Data Section Programmatically.

    To add a Simulink enumeration defined by Simulink.data.dictionary.EnumTypeDefinition with a specified name to the Architectural Data section of a data dictionary, use the addEnumType function and specifying the name-value argument EnumTypeDefition with the Simulink.data.dictionary.EnumTypeDefinition object.

    Create a Simulink.data.dictionary.EnumTypeDefinition object. By default, the new type defines a single enumeration member enum1 with underlying integer value 0. Add enumeration members to the type definition by using the appendEnumeral function.

    myShapes = Simulink.data.dictionary.EnumTypeDefinition;
    appendEnumeral(myShapes,"Line",1);
    appendEnumeral(myShapes,"Triangle",3);
    appendEnumeral(myShapes,"Square",4);
    appendEnumeral(myShapes,"Pentagon",5);
    myShapes
    myShapes = 
    
       Simulink.data.dictionary.EnumTypeDefinition
          enum1
          Line
          Triangle
          Square
          Pentagon

    Remove the first enumeration member from the type definition by using the removeEnumeral function.

    removeEnumeral(myShapes,1);
    myShapes
    myShapes = 
    
       Simulink.data.dictionary.EnumTypeDefinition
          Line
          Triangle
          Square
          Pentagon

    To store the enumerated type definition in the Architectural Data section of a data dictionary use the addEnumType function and specify the EnumTypeDefinition name-value argument.

    dictName = "dataDictionary.sldd";
    archData = Simulink.dictionary.archdata.create(dictName);
    shapesArch = addEnumType(archdata,"MyShapes",...
        EnumTypeDefinition=myShapes)
    shapesArch = 
      EnumType with properties:
    
                Name: 'MyShapes'
         Description: 'These are my favorite shapes.'
        DefaultValue: 'Line'
         StorageType: 'Native Integer'
           Enumerals: [1×5 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    For more information regarding storing architectural data in a data dictionary, see Store Data in Architectural Data Section Programmatically.

    Input Arguments

    collapse all

    Architectural Data object, specified as a Simulink.dictionary.ArchitecturalData object.

    Name of the enumerated data type in the Architectural Data section represented by archData, specified as a character vector or string scalar.

    Example: "airSpeed"

    Simulink enumerated data type object, specified as a Simulink.data.dictionary.EnumTypeDefinition object.

    Output Arguments

    collapse all

    Enumerated data type object, returned as Simulink.dictionary.archdata.EnumType object.

    Version History

    Introduced in R2023b