Main Content

Simulink.dictionary.archdata.Enumeral

Enumeration member of enumerated data type stored in Architectural Data section

Since R2023b

    Description

    Use a Simulink.dictionary.archdata.Enumeral object to represent enumeration member of a Simulink.dictionary.archdata.EnumType object in the Architectural Data section of a data dictionary.

    Creation

    You can add enumeration members to an enumerated data type in the Architectural Data section of a data dictionary in two ways:

    • Interactively create a Simulink.dictionary.archdata.Enumeral object by using the Architectural Data Editor.

    • Programmatically create a Simulink.dictionary.archdata.Enumeral object by using the addEnumeral function.

    Properties

    expand all

    Name of enumeration member, specified as a character vector or string scalar.

    Example: "Line"

    Data Types: char | string

    Architectural Data section containing the enumerated data type, specified as a Simulink.dictionary.ArchitecturalData object.

    Example: Owner: [1×1 Simulink.dictionary.ArchitecturalData]

    Value of an enumeration member, specified as a character vector, string scalar, or real scalar integer. The value must be compatible with the StorageType property of the parent enumerated data type.

    Example: "3"

    Data Types: char | string | int8 | int16 | int32 | uint8 | uint16 | uint32

    Custom description of the enumeration member of an enumerated data type stored in the Architectural Data section of a data dictionary, specified as a character vector or string scalar.

    Example: 'This enumeration member is a triangle. A triangle has three sides.'

    Data Types: char | string

    Examples

    collapse all

    Create a data dictionary.

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

    Add an enumerated data type using the addEnumType function.

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

    Use the properties of the enumerated data type object to specify the name and storage type, and to write a description of the enumerated data type.

    set(MyAnimals,"Description","These are my favorite animals.");
    set(MyAnimals,"StorageType","Native Integer");
    MyAnimals
    MyAnimals = 
      EnumType with properties:
    
                Name: 'animalsRanked'
         Description: 'These are my favorite animals.'
        DefaultValue: 'enum1'
         StorageType: 'Native Integer'
           Enumerals: [1×1 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]
    

    Add enumeration members to the architectural enumerated data type by using the addEnumeral function.

    addEnumeral(MyAnimals,"Ibex",'6',"Not actually a deer.");
    addEnumeral(MyAnimals,"Deer",'5',"Actually a deer.");
    addEnumeral(MyAnimals,"Wolf",'4',"Hunts deer.");
    addEnumeral(MyAnimals,"Turtle",'3',"Sometimes friendly, mostly slow.");
    addEnumeral(MyAnimals,"Cat",'2',"Cute and fluffy.");
    addEnumeral(MyAnimals,"Dog",'1',"Faithful companion.");
    MyAnimals
    MyAnimals = 
      EnumType with properties:
    
                Name: 'animalsRanked'
         Description: 'These are my favorite animals.'
        DefaultValue: 'enum1'
         StorageType: 'Native Integer'
           Enumerals: [1×7 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]
    

    You can then use the enumeration members to define the DefaultValue of the architectural enumerated data type object.

    set(MyAnimals,"DefaultValue","Dog");
    MyAnimals
    MyAnimals = 
      EnumType with properties:
    
                Name: 'animalsRanked'
         Description: 'These are my favorite animals.'
        DefaultValue: 'Dog'
         StorageType: 'Native Integer'
           Enumerals: [1×7 Simulink.dictionary.archdata.Enumeral]
               Owner: [1×1 Simulink.dictionary.ArchitecturalData]
    

    To retrieve an enumeration member, use the getEnumeral function.

    enumMember = getEnumeral(MyAnimals,"enum1")
    enumMember = 
    
      Enumeral with properties:
    
               Name: 'enum1'
              Value: '0'
        Description: ''

    To remove an enumeration member from an enumerated data type, use the removeEnumeral function.

    removeEnumeral(MyAnimals,"enum1");
    getEnumeralNames(MyAnimals)'
    ans =
    
      6×1 cell array
    
        {'Ibex'  }
        {'Deer'  }
        {'Wolf'  }
        {'Turtle'}
        {'Cat'   }
        {'Dog'   }

    Version History

    Introduced in R2023b