Main Content

appendEnumeral

Class: Simulink.data.dictionary.EnumTypeDefinition
Package: Simulink.data.dictionary

Add enumeration member to enumerated data type definition in data dictionary

Syntax

appendEnumeral(typeObj,memberName,memberValue,memberDesc)

Description

appendEnumeral(typeObj,memberName,memberValue,memberDesc) adds an enumeration member to the enumerated type definition stored by typeObj, a Simulink.data.dictionary.EnumTypeDefinition object.

Input Arguments

expand all

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

Name of the new enumeration member, specified as a character vector.

Example: 'myNewEnumMember'

Data Types: char

Integer value underlying the new enumeration member, specified as an integer.

The definition of the enumeration class determines the integer data type used in generated code to store the underlying values of enumeration members.

Example: 3

Data Types: single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | double

Description of the new enumeration member, specified as a character vector.

If you do not want to supply a description for the enumeration member, use an empty character vector.

Example: 'Enumeration member number 1.'

Example: ''

Data Types: char

Examples

expand all

Create an object that can store the definition of an enumerated type. By default, the new type defines a single enumeration member enum1 with underlying integer value 0.

myColors = Simulink.data.dictionary.EnumTypeDefinition
myColors = 

   Simulink.data.dictionary.EnumTypeDefinition
      enum1

Add some enumeration members to the definition of the type.

appendEnumeral(myColors,'Orange',1,'')
appendEnumeral(myColors,'Black',2,'')
appendEnumeral(myColors,'Cyan',3,'')
myColors
myColors = 

   Simulink.data.dictionary.EnumTypeDefinition
      enum1
      Orange
      Black
      Cyan

Remove the default enumeration member enum1. Since enum1 is the first enumeration member in the list, identify it with index 1.

removeEnumeral(myColors,1)
myColors
myColors = 

   Simulink.data.dictionary.EnumTypeDefinition
      Orange
      Black
      Cyan

Customize the enumerated type by configuring the properties of the object representing it.

myColors.Description = 'These are my favorite colors.';
myColors.DefaultValue = 'Cyan';
myColors.HeaderFile = 'colorsType.h';

Open the data dictionary myDictionary_ex_API.sldd and represent it with a Simulink.data.Dictionary object named myDictionaryObj.

myDictionaryObj = Simulink.data.dictionary.open('myDictionary_ex_API.sldd');

Import the object that defines the enumerated type myColors to the dictionary.

importFromBaseWorkspace(myDictionaryObj,'varList',{'myColors'});

Alternatives

You can use Model Explorer to add enumeration members to the enumerated data type represented by a Simulink.data.dictionary.EnumTypeDefinition object.

Introduced in R2015a