MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

a = 6;
b


b =
8


Clearing a does not affect b:


clear a
b


b =
8


Value Object Properties


The copy behavior of values stored as properties in value objects is the same as numeric
variables. For example, suppose vobj1 is a value object with property a:


vobj1.a = 8;


If you copy vobj1 to vobj2, and then change the value of vobj1 property a, the value of
the copied object's property, vobj2.a, is unaffected:


vobj2 =vobj1;
vobj1.a = 5;
vobj2.a


ans =
8


Handle Object Copy Behavior


Here is a handle class called HdClass that defines a property called Data.


classdef HdClass < handle
properties
Data
end
methods
function obj = HdClass(val)
if nargin > 0
obj.Data = val;
end
end


Object Behavior
Free download pdf