MATLAB Object-Oriented Programming

(Joyce) #1

end
end


MATLAB considers a and b as equivalent:


a = WeekDays.Monday;
b = WeekDays.Monday;
isequal(a,b)


ans =


1


a == b


ans =


1


Enumeration Member Properties Remain Constant


Value-based enumeration classes that define properties are immutable. For example, the
Colors enumeration class associates RGB values with color names.


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


The constructor assigns the input arguments to R, G, and B properties:


red = Colors.Red;
[red.R,red.G,red.B]


Mutable Handle vs. Immutable Value Enumeration Members
Free download pdf