我希望对象的属性对用户可见,但用户不能修改。我尝试过以下方法
classdef myObject < handle
properties (Access = private, Hidden = false)
property
end
但是这个对用户来说仍然是隐藏的,我在文档中找不到任何可以做到这一点的内容。有没有办法使该属性“只读”?
最佳答案
除了 Access
属性之外,还有 GetAccess
和 SetAccess
属性。请参阅the documentation for these .
classdef myObject < handle
properties (SetAccess = private)
property
end
请注意,Access
是一个伪属性,是将 GetAccess
和 SetAccess
设置为相同值的简写。
关于MATLAB 对象属性可见但不可修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56856286/