Main Content

Simulink.defineIntEnumType

Define enumerated data type

Description

Simulink.defineIntEnumType(ClassName,"Members",{{EnumName1,EnumIntValue1},...,{EnumNameN,EnumIntValueN}}) defines an enumeration named ClassName where each member has a name and numeric value specified by EnumName and EnumIntValue respectively.

example

Simulink.defineIntEnumType(ClassName,"Members",{{EnumName1,EnumIntValue1,"Description",EnumDescription1},...,{EnumNameN, EnumIntValueN,"Description",EnumDescriptionN}}) defines an enumeration named ClassName where each member has a name, numeric value, as in the previous syntax, and optionally includes a description specified by EnumDescription.

example

Simulink.defineIntEnumType(___,Name=Value) specifies options using one or more name-value arguments in addition to the input arguments in the previous syntax. For example, to import a data type definition from an external header file, set DataScope to Imported.

example

Examples

collapse all

Assume an external data dictionary includes the following enumeration:

TrafficColors.Red(0),TrafficColors.Yellow(1),TrafficColors.Green(2)

Import the enumeration class definition into the MATLAB® workspace from header file mytrafficcolors.h while specifying that the enumeration values in generated code are tunable and have the underlying integer data type int16.

Simulink.defineIntEnumType("TrafficColors", ... 
	"Members",{{"Red",0,"Description","Stop!"}, ...
       {"Yellow",1,"Description","Prepare to stop!"}, ...
       {"Green",2,"Description","Go!"}}, ... 
	Description="Traffic light colors", ...
	DefaultValue="Green", ...
	HeaderFile="mytrafficcolors.h", ...
	DataScope="Imported", ...
	AddClassNameToEnumNames=true, ...
	StorageType="int16", ...
      IsTunableInCode=true);

Input Arguments

collapse all

The name of the enumerated data type, specified as a character vector or string scalar.

Example: BasicColors

Data Types: char | string

Enumeration member name, specified as a character vector or string scalar.

Example: "Yellow"

Data Types: char | string

Numeric enumeration member value, specified as a numeric value. For uint32-based enumerations, enumeration value must be less than or equal to intmax("int32").

Example: 1

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

Since R2026a

Enumeration member description, specified as a character vector or string scalar.

Example: "Prepare to stop!"

Data Types: char | string

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: Simulink.defineIntEnumType("TrafficColors","Members",{{"Red",0,"Description","Stop!"},{"Yellow",1,"Description","Prepare to stop!"},{"Green",2,"Description", "Go!"}},HeaderFile="mytrafficcolors.h",DataScope="Imported"); sets DataScope to Imported and specifies for the code generator to import the enumerated type definition from external file mytrafficcolors.h.

Description of the enumeration data type, specified as a character vector or string scalar.

Example: "Basic colors"

The default enumeration value, specified as a character vector or string. The value is one of the values specified for CellOfEnums.

Example: "Blue"

Action to take for the data type definition during code generation, specified as one of these values:

  • "Auto" — If no value is specified for HeaderFile, export the type definition to model_types.h where model is the model name. If a value is specified for HeaderFile, import the data type definition from the specified header file.

  • "Exported" — Export the data type definition to a header file. If no value is specified for HeaderFile, the header file name defaults to type.h, where type is the data type name.

  • "Imported" — Import the data type definition from a header file. If no value is specified for HeaderFile, the header file name defaults to type.h, where type is the data type name.

To avoid MISRA C:2012 and MISRA C:2023 violations, set the data scope selection to "Imported" or "Exported".

The external header file that contains the data type definition, specified as a character vector or string. By default, the generated #include directive uses the preprocessor delimiter " instead of < and >. To generate the directive #include <mytypes.h>, specify HeaderFile as '<myTypes.h>'.

Example: 'mybasiccolors.h'

Whether the code generator applies the class name as a prefix to the enumerations, specified as a numeric or logical 1 (true) or 0 (false).

Example: true

Data type used to store the enumerations' underlying integer values in generated code, specified as a string.

Example: "int16"

Since R2025a

Option to enable tunability (changing, adding, and reordering) of enumeration values in generated code, specified as a numeric or logical 1 (true) or 0 (false). To set this argument to true, you must set DataScope to "Imported".

Example: true

Version History

Introduced in R2010b

expand all