how can I auto-link two properites in a matlab class
3 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I am relatively new to the object-oriented programming in Matlab (though I have vast experience working with non-object-oriented Matlab).
Here's my question.
I have two parameters in a class that I want to link. For example, y = f(x) and as soon as x changes, 7 should change as well.
As soon as 'x' changes, 'y' should reflect that change as well. The value of 'y' is depended on the opearion of function 'my_func' below. How can I do that?
I am flexibile in the implementation and if it can be done without methods (ie within properties), I am happy with that too.
classdef MyClass
properties
x
y
end
methods
function b = my_func(a)
if x <10
y = 1;
elseif x>=10 && x < 50;
y=2;
else
y = 3;
end
end
end
end
0 件のコメント
採用された回答
Steven Lord
2021 年 12 月 13 日
Make x and/or y dependent properties, either having the get.y method perform its computations using the value of the x property or having both depend on a third property. For example, if you had area and perimeter properties of an object they could both be Dependent and use the value of a property that stores the coordinates of the vertices of that object.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で MATLAB Classes についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!