How do I use the SUBSREF function to behave as the BUILTIN only for a subset of subscripted references in MATLAB 7.8(R2009a)?
Show older comments
I would like to create a SUBSREF function for my class. I am coding the SUBSREF method to behave like a custom SUBSREF for a subset of the subscription symbols and behave like the builtin SUBSREF for the rest. This presents a challenge, as the private and protected properties and methods are accessible inside the custom SUBSREF function. What steps can I take to make sure my private and protected properties and methods are not visible?
Reproduction Steps:
classdef testclass
properties (Access = protected)
prop1 = 1;
prop2 = 2;
end
% constructor
methods (Access = public)
function TC = testclass()
end
end
% Overloaded subsref
methods
function vals = subsref(TC,s)
switch s(1).type
case '.'
vals = builtin('subsref',TC,s);
case '()'
end
end
end
methods (Access = protected)
function showvals(TC)
disp('prop1 =');
disp(TC.prop1);
disp('prop2 =');
disp(TC.prop2);
end
end
end
t = testclass
t.prop1
Accepted Answer
More Answers (0)
Categories
Find more on Class Introspection and Metadata in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!