MATLAB: How to declare class member data public

classdataMATLABmemberobjectpublicsubsasgnsubsref

I would like to make class member data accessible from non-member functions through subscript (dot) notation, as in C++.

Best Answer

This behavior is supported by implementing the SUBSREF and SUBSASGN members for an object. These are invoked to handle the following cases:
A=MyClass(initial)
out = A(I)% Invoke out=A.SUBSREF(A,S)
out = A{I}
out = A.field
A(I) = in% Invoke A.SUBSASN(A,S,in)
A{I} = in
A.field = in
where S is a structure that describes the type of indexing.
More information about the SUBSASGN and SUBSREF commands can be found here:
https://www.mathworks.com/help/matlab/ref/subsasgn.html