change variable in a class
조회 수: 12 (최근 30일)
이전 댓글 표시
I have two classes, whereas the second class is to be called by the first one.
classdef sender < handle
properties
Bitvektor;
end
properties (Access = private)
kobj;
end
methods
function obj = sender(variable)
obj.Bitvektor = variable;
obj.kobj = kanal; %initialize class kanal
end
function u = sendeBitvektor(obj)
obj.kobj.Bitvektor = obj.Bitvektor;
u = obj.kobj.sendtoreceiver; % call function in class kanal
end
end
end
%%%%%
classdef kanal < handle
properties
Bitvektor
Delta
end
methods
function on = kanal(obj)
on.Bitvektor ;
on.Delta
end
end
methods
function u = sendtoreceiver(on)
on.Delta
end
end
end
Now if i try to change delta in kanal the value seems to be changed.
delta = 0.05;
kanal.Delta = delta
However, if i call the function sendtoreceiver, it appears, that the value wasn't assigned to delta.
Sender is not supposed to know delta.
How do i permanently change the value of delta, such that if i call the function sendtoreceiver delta is already assigned ?
Thanks for every help
댓글 수: 0
채택된 답변
Vimal Rathod
2020년 12월 6일
Hi,
As kanal object is a private variable in sender class, any user will not be able to access that object and set any variable to the delta field and to assign value of delta you have to create a set method or you could assign the variable with a value in the constructor only.
Refer to the following link to know more details about constructor
Refer to the following link to know more about set methods
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!