필터 지우기
필터 지우기

Saving System Objects With Children System Objects

조회 수: 1 (최근 30일)
Jeremy Reed
Jeremy Reed 2019년 3월 7일
Say that I have two system objects, x and y, that are from classes obj1 and obj2, respectively. Also, obj1 is a child to obj2.
x = obj1;
y = obj2('Prop1',obj1); %Obj1 is a child to Obj2
If I change a property of x, the it changes for y as well.
x.propA = 10; % Now, y.Prop1.propA is 10 as well
The reason is that system objects are also handle objects, so x and y are really pointers to objects. Thus, to save and load the variables, I need to include the following code in my class definitions for obj2:
methods (Access = protected)
function s = saveObjectImpl(obj)
s.Prop1 = matlab.System.saveObject(obj.Prop1);
end
function loadObjectImpl(obj,s,wasInUse)
obj.Prop1 = matlab.System.loadObject(s.Prop1);
end
end
However, now if I load my workspace and then chagnge x, it no longer changes y!
load my_workspace
x.propA = 20; %x.propA =20, but y.Prop1.propA still is 10
In other words, the pointer link is broken and really two separate objects are created during the load. Is there a way to fix this?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Create System Objects에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by