MATLAB Object-Oriented Programming

(Joyce) #1
Example Code Discussion
function b = subsref(a,s)
switch s(1).type
case '()'
ind = s.subs{:};
b = polyval(a.coef,ind);
case '.'
switch s(1).subs
case 'coef'
b = a.coef;
case 'disp'
disp(a)
otherwise
if length(s)>1
b = a.(s(1).subs)(s(2).subs{:});
else
b = a.(s.subs);
end
end
otherwise
error('Specify value for x as obj(x)')
end
end

Redefine indexed reference for
DocPolynom objects.

For information about this code,
see “Redefine Indexed
Reference” on page 19-19

19 Defining Custom Data Types

Free download pdf