How do I create enumerated types in MATLAB?

iddober picture iddober · Sep 7, 2009 · Viewed 38.1k times · Source

Are there enumerated types in MATLAB? If not, what are the alternatives?

Answer

Jonas picture Jonas · Nov 6, 2010

Starting from R2010b, MATLAB supports enumerations.

Example from the documentation:

classdef Colors
   properties
      R = 0;
      G = 0;
      B = 0;
   end

   methods
      function c = Colors(r, g, b)
         c.R = r; c.G = g; c.B = b;
      end
   end

   enumeration
      Red   (1, 0, 0)
      Green (0, 1, 0)
      Blue  (0, 0, 1)
   end
end