Main Content

Simulink.defineIntEnumType

Define enumerated data type

Description

Simulink.defineIntEnumType(ClassName,CellOfEnums,IntValues) defines an enumeration named ClassName with enumeration values specified with CellOfEnums and underlying numeric values specified by IntValues.

example

Simulink.defineIntEnumType(ClassName,CellOfEnums,IntValues,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.

Examples

collapse all

Assume an external data dictionary includes the following enumeration:

BasicColors.Red(0), BasicColors.Yellow(1), BasicColors.Blue(2)

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

Simulink.defineIntEnumType(BasicColors, ... 
	{"Red","Yellow","Blue"},[0;1;2], ... 
	Description="Basic colors", ...
	DefaultValue="Blue", ...
	HeaderFile="mybasiccolors.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.

Example: BasicColors

Enumerations for the data type, specified as a cell array of character vectors or strings.

Example: {"Red", "Yellow", "Blue"}

Numeric enumeration values, specified as an array. For uint32-based enumerations, enumeration values must be less than or equal to intmax('int32').

Example: [0;1;2]

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(BasicColors, ...{"Red","Yellow","Blue"},[0;1;2],DataScope,"Imported",FileName,"MyBasicColors.h"); sets ScopeSelection to Imported and specifies for the code generator to import the enumerated type definition from external file mybasiccolors.h.

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

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 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 FileName 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