MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
end
end

Create an object of this class:

hobj1 = HdClass(8)

Because this statement is not terminated with a semicolon, MATLAB displays information
about the object:

hobj1 =

HdClass with properties:

Data: 8

The variable hobj1 is a handle that references the object created. Copying hobj1 to
hobj2 results in another handle referring to the same object:

hobj2 = hobj1

hobj2 =

HdClass with properties:

Data: 8

Because handles reference the object, copying a handle copies the handle to a new
variable name, but the handle still refers to the same object. For example, given that
hobj1 is a handle object with property Data:

hobj1.Data

ans =

8

Change the value of hobj1's Data property and the value of the copied object's Data
property also changes:

hobj1.Data = 5;
hobj2.Data

ans =

5

16 Using Objects

Free download pdf