Borrar filtros
Borrar filtros

Saving System Objects With Children System Objects

1 visualización (últimos 30 días)
Jeremy Reed
Jeremy Reed el 7 de Mzo. de 2019
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?

Respuestas (0)

Categorías

Más información sobre Create System Objects en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by