Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create enumerated types in MATLAB?

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

like image 755
iddober Avatar asked Sep 07 '09 11:09

iddober


People also ask

How do you declare enumerated data types?

In this situation, one can declare the enumerated type in which only male and female values are assigned. It can be declared during declaring enumerated types, just add the name of the variable before the semicolon. or, Beside this, we can create enumerated type variables as same as the normal variables.

How do you declare an enumeration?

An enum is defined using the enum keyword, directly inside a namespace, class, or structure. All the constant names can be declared inside the curly brackets and separated by a comma. The following defines an enum for the weekdays. Above, the WeekDays enum declares members in each line separated by a comma.

What is enumerated data type with example?

An enumerated type is a type whose legal values consist of a fixed set of constants. Common examples include compass directions, which take the values North, South, East and West and days of the week, which take the values Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday.


1 Answers

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 
like image 75
Jonas Avatar answered Sep 30 '22 06:09

Jonas