MATLAB Object-Oriented Programming

(Joyce) #1

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


Create an instance of HandleColors.Red and return the value of the R property:


a = HandleColors.Red;
a.R


ans =


1


MATLAB constructs the HandleColors.Red enumeration member, which sets the R
property to 1 , the G property to 0 , and the B property to 0.


Change the value of the R property to 0.8:


a.R = 0.8;


After setting the value of the R property to 0.8, create another instance, b, of
HandleColors.Red:


b = HandleColors.Red;
b.R


ans =


0.8000


The value of the R property of the newly created instance is also 0.8. A MATLAB session
has only one value for any enumeration member at any given time.


Clearing the workspace variables does not change the current definition of the
enumeration member HandleColors.Red:


clear
a = HandleColors.Red;
a.R


ans =


0.8000


Mutable Handle vs. Immutable Value Enumeration Members
Free download pdf