Property access attributes cannot be modified at runtime in MATLAB.
However, there are ways to prevent the program from modifying the values of a property, once it has been "locked".
Approach 1:
Define the 'SetAccess' attribute for the property of class A that holds the object of class B as 'immutable'. Similarly define all properties of class B as 'immutable'. In this way, you can only set the values of the properties for the first time in the constructor.
Approach 2:
A more flexible approach is to define a flag property, and write your own code for 'set.propertyname' method in the class A. In this method, the property which contains the handle to object of class B, should be modified only if the flag is reset. Note that once the handle is available the user would still be able to read it, and modify the object of class B, but cannot modify the handle itself. As an example:
methods
set.propertyname(object,value)
end
end
Further, to avoid modifying the object of class B, the value of flag would have to be queried from object of class A and implement a logic similar to the one above to make each property modifiable/not modifiable.
Best Answer