Mercurial > octave
view examples/code/@polynomial/subsref.m @ 21059:73ab962bc52d
doc: Use newer coding conventions in examples/code directory.
* FIRfilter.m, FIRfilter_aggregation.m, display.m, subsasgn.m, subsref.m,
display.m, end.m, get.m, numel.m, plot.m, polynomial.m,
polynomial_superiorto.m, polyval.m, roots.m, set.m, subsasgn.m, subsref.m,
celldemo.cc, fortrandemo.cc, funcdemo.cc, globaldemo.cc, oct_demo.cc,
paramdemo.cc, stringdemo.cc:
Use newer coding conventions in examples/code directory.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 13 Jan 2016 16:21:24 -0800 |
parents | 25d676f9619c |
children | fd97ed44f2da |
line wrap: on
line source
function b = subsref (a, s) if (isempty (s)) error ("@polynomial/subsref: missing index"); endif switch (s(1).type) case "()" ind = s(1).subs; if (numel (ind) != 1) error ("@polynomial/subsref: need exactly one index"); endif b = polyval (fliplr (a.poly), ind{1}); case "{}" ind = s(1).subs; if (numel (ind) != 1) error ("@polynomial/subsref: need exactly one index"); endif if (isnumeric (ind{1})) b = a.poly(ind{1}+1); else b = a.poly(ind{1}); endif case "." fld = s.subs; if (! strcmp (fld, "poly")) error ("@polynomial/subsref: invalid property \"%s\"", fld); endif b = a.poly; otherwise error ("@polynomial/subsref: invalid subscript type"); endswitch if (numel (s) > 1) b = subsref (b, s(2:end)); endif endfunction