Simulink.defineIntEnumType - Define enumerated data type - MATLAB (original) (raw)
Define enumerated data type
Syntax
Description
Simulink.defineIntEnumType([ClassName](#mw%5Fbaf58925-526c-4e49-8e68-79dc9f743989),[CellOfEnums](#mw%5F1a9b69ee-fa33-443e-9b7a-1974e1b86d02),[IntValues](#mw%5F9ed8332f-ec85-4248-8a52-724c6e00b601))
defines an enumeration named ClassName
with enumeration values specified with CellOfEnums
and underlying numeric values specified byIntValues
.
Simulink.defineIntEnumType([ClassName](#mw%5Fbaf58925-526c-4e49-8e68-79dc9f743989),[CellOfEnums](#mw%5F1a9b69ee-fa33-443e-9b7a-1974e1b86d02),[IntValues](#mw%5F9ed8332f-ec85-4248-8a52-724c6e00b601),[Name=Value](#namevaluepairarguments))
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
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
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. Foruint32
-based enumerations, enumeration values must be less than or equal to intmax('int32')
.
Example: [0;1;2]
Name-Value Arguments
Specify optional pairs of arguments asName1=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 filemybasiccolors.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 forHeaderFile
, export the type definition tomodel_types.h
wheremodel
is the model name. If a value is specified forHeaderFile
, 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 forHeaderFile
, the header file name defaults totype.h
, wheretype
is the data type name."Imported"
— Import the data type definition from a header file. If no value is specified forHeaderFile
, the header file name defaults totype.h
, wheretype
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