How can I make a property of a MATLAB class such that it can be read from outside the class but cannot be set from outside the class? For example, I want the sensor property (below) to only be settable from within the Data class, while also being readable from outside it.
classdef Data
properties
sensor;
end
end
classdef Data
properties(SetAccess=protected, GetAccess=public)
sensor;
end
end
You can use SetAccess=private instead, if you don't want inheriting classes to have writeable access either.
The default behavior for SetAccess and GetAccess is public, so you don't need to explicitly state GetAccess=public here, but it does not hurt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With