I am confused on how to use handle objects as properties in matlab. For example, I defined the following classes:
classdef Page < handle
properties
word1;
word2;
end
classdef Book < handle
properties
page1 = Page;
page2 = Page;
end
Now I instantiate two books:
iliad = Book;
odyssey = Book;
If I check if iliad and odyssey are the same:
eq(iliad, odyssey)
I get:
ans = logical 0
So far so good
But if I check if page1 of iliad and odyssey are the same:
eq(iliad.page1, odyssey.page1)
I get:
ans = logical 1
This is not good! It means that if I change page1 of odyssey, page1 of iliad will also change. What am I misunderstanding? How do I deal with this issue?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…