Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Using Enumerated Data in MATLAB Function Blocks

When to Use Enumerated Data

You can use enumerated types to represent program states and to control program logic, especially when you need to restrict data to a finite set of values and refer to these values by name. Even though you can sometimes achieve these goals by using integers or strings, enumerated types offer the following advantages:

  • Provide more readable code than integers

  • Allow more robust error checking than integers or strings

    For example, if you mistype the name of an element in the enumerated type, the code generation software alerts you that the element does not belong to the set of allowable values.

  • Produce more efficient code than strings

    For example, comparisons of enumerated values execute faster than comparisons of strings.

Limitations of Enumerated Types

Enumerated types in MATLAB Function blocks are subject to the limitations imposed by the code generation software. See Enumerated Data Definition for Code Generation.

Was this topic helpful?