defining properties in a class
4 次查看(过去 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
13 个评论
Rik
2021-8-3
Why would it? This is what it returns with your classdef.
I don't understand why you instist on calling things static when they aren't.
main(10)
function main(arg)
classname.fun1(arg,arg)
end
另请参阅
类别
在 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!