How to get Dependent Property depending on properties of objects of different class
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Matt J
2013 年 10 月 2 日
編集済み: Matt J
2013 年 10 月 2 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Software Development Tools についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!