MATLAB Object-Oriented Programming

(Joyce) #1

Number: 1


Assign the value of a to another variable, b.


b = a


b =


NumValue with properties:


Number: 1


The variables a and b are independent. Changing the value of the Number property of a
does not affect the Number property of b.


a.Number = 7


a =


NumValue with properties:


Number: 7


b


b =


NumValue with properties:


Number: 1


Modifying Value Objects in Functions


When you pass a value object to a function, MATLAB creates a copy of that object in the
function workspace. Because copies of value objects are independent, the function does
not modify the object in the caller’s workspace. Therefore, functions that modify value
objects must return the modified object to be reassigned in the caller’s workspace.


For more information, see “Object Modification” on page 5-63.


User-Defined Handle Classes


Instances of classes that derive from the handle class are references to the underlying
object data. When you copy a handle object, MATLAB copies the handle, but does not


Comparison of Handle and Value Classes
Free download pdf