defining properties in a class
조회 수: 1(최근 30일)
표시 이전 댓글
I have the following class
classdef classname
properties (Constant)
Number=1
end
end
I can change the value of `Number`
classname.Number=2
How can I defined properties so that one cannot change the value of the variables defined in `properties`?
댓글 수: 0
답변(1개)
Rik
2021년 8월 3일
편집: Rik
2021년 8월 3일
This doc page seems to suggest this is not natively possible. However, you could implement it as method:
%(untested code)
classdef classname
properties (Private)
%use a struct to store the defaults to keep all your static
%properties in one place
static.Number=1;
end
methods
function val=Number(obj)
val=obj.static.Number;
end
end
end
참고 항목
범주
Find more on Software Development Tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!