How to get Dependent Property depending on properties of objects of different class
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Matt J
le 2 Oct 2013
Modifié(e) : Matt J
le 2 Oct 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Software Development Tools dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!