How to get Dependent Property depending on properties of objects of different class
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
J. Hu
el 2 de Oct. de 2013
Comentada: Matt J
el 2 de Oct. de 2013
See the code below:
Ex_ObjA.m-->
classdef Ex_ObjA
properties
a
end
methods
function Obj=Ex_ObjA(t)
Obj.a = t;
end
end
end
Ex_ObjBC.m-->
classdef Ex_ObjBC
properties
b
end
properties (Dependent = true, SetAccess = public)
c
end
methods
function Obj=Ex_ObjBC(t)
Obj.b = t;
end
function c=get.c(Obj,s1) % error: Get methods must have exactly one input
c = Obj.b + s1.a;
end
end
end
I tried to do following:
s1 = Ex_ObjA(2);
s2 = Ex_ObjBC(3);
s2.c
Not successful, because "Get methods must have exactly one input". So I can pass the s1.a to Ex_ObjBC to get s1.c?
Much appreciation!!!
0 comentarios
Respuesta aceptada
Matt J
el 2 de Oct. de 2013
Editada: Matt J
el 2 de Oct. de 2013
There's no apparent reason why c should be a property, Dependent or otherwise. You could just write the class this way,
classdef Ex_ObjBC
properties
b
end
methods
function Obj=Ex_ObjBC(t)
Obj.b = t;
end
function out=c(Obj,s1)
out = Obj.b + s1.a;
end
end
end
4 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!