It seems like Matlab's 'builtin' function doesn't work when subsref is overloaded in a class. Consider this class:
classdef TestBuiltIn properties testprop = 'This is the built in method'; end methods function v = subsref(this, s) disp('This is the overloaded method'); end end end
To use the overloaded subsref method, I do this:
t = TestBuiltIn; t.testprop >> This is the overloaded method
That's as expected. But now I want to call Matlab's built in subsref method. To make sure I'm doing things right, first I try out a similar call on a struct:
x.testprop = 'Accessed correctly'; s.type = '.'; s.subs = 'testprop'; builtin('subsref', x, s) >> Accessed correctly
That's as expected as well. But, when I try the same method on TestBuiltIn:
builtin('subsref', t, s) >> This is the overloaded method
…Matlab calls the overloaded method rather than the built in method. Why does Matlab call the overloaded method when I requested that it call the builtin method?
Best Answer