Define Enumerated Data Types for MATLAB Function Blocks

You can define enumerated data types for MATLAB Function blocks in two ways:

Define Enumerated Type in Class Definition File

  1. Create a class definition file.

    In the Command Window, select File > New > Class.

  2. Enter the class definition:

    classdef(Enumeration) EnumTypeName < BaseType

    EnumTypeName is a case-sensitive string that must be unique among data type names and workspace variable names. BaseType must be Simulink.IntEnumType, int8, uint8, int16, uint16, or int32.

    For example, the following code defines an enumerated type called sysMode that inherits from the built-in type Simulink.IntEnumType:

    classdef(Enumeration) sysMode < Simulink.IntEnumType
        ...
    end
  3. Define enumerated values in an enumeration section:

    classdef(Enumeration) EnumTypeName < BaseType
      enumeration
        EnumName(N)
        ...
      end
    end

    For example, the following code defines a set of two values for enumerated type LEDcolor:

    classdef(Enumeration) LEDcolor < Simulink.IntEnumType
        enumeration
            GREEN(1),
            RED(2),
        end
    end
  4. Save the file on the MATLAB® path.

    The name of the file must match the name of the enumerated data type. The match is case sensitive.

For more information about the supported base types, see Enumerated Types Supported in MATLAB Function Blocks.

Was this topic helpful?