Main Content

Simulink.defineIntEnumType

Define enumerated data type

Description

example

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

Simulink.defineIntEnumType(___,'Description',ClassDesc) defines the enumeration with a description.

Simulink.defineIntEnumType(___,'DefaultValue',DefValue) defines a default value for the enumeration, which is one of the character vectors you specify for CellOfEnums.

Simulink.defineIntEnumType(___,'DataScope',ScopeSelection) specifies whether the data type definition should be imported from, or exported to, a header file during code generation.

Simulink.defineIntEnumType(___,'HeaderFile',FileName) specifies the name of a header file containing the enumeration class definition for use in code generated from a model.

Simulink.defineIntEnumType(___,'AddClassNameToEnumNames',Flag) specifies whether the code generator applies the class name as a prefix to the enumeration values that you specify for CellOfEnums. For Flag, specify true or false. For example, if you specify true, the code generator would use BasicColors.Red instead of Red to represent an enumerated value.

Simulink.defineIntEnumType(___,'StorageType',DataType) specifies the data type used to store the enumerations’ underlying integer values in code generated from a model.

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 while specifying int16 as the underlying integer data type for generated code:

Simulink.defineIntEnumType('BasicColors', ... 
	{'Red', 'Yellow', 'Blue'}, ...
	[0;1;2], ... 
	'Description', 'Basic colors', ...
	'DefaultValue', 'Blue', ...
	'HeaderFile', 'mybasiccolors.h', ...
	'DataScope', 'Exported', ...
	'AddClassNameToEnumNames', true, ...
	'StorageType', 'int16');

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.

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

Numeric enumeration values, specified as an array.

Example: [0;1;2]

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

Example: 'Basic colors'

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

Example: 'Blue'

That header file that is to contain the data type definition, specified as a character vector. 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'

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.

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 character vector.

Example: 'int16'

Introduced in R2010b