Mercurial > forge
changeset 9623:40a1e6b36726 octave-forge
control: use recursion instead of for-loop for subs ref
author | paramaniac |
---|---|
date | Sat, 10 Mar 2012 19:45:06 +0000 |
parents | cdf1dbf20cd4 |
children | dbea4e0ca957 |
files | main/control/inst/@lti/subsref.m |
diffstat | 1 files changed, 24 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/main/control/inst/@lti/subsref.m Sat Mar 10 16:03:47 2012 +0000 +++ b/main/control/inst/@lti/subsref.m Sat Mar 10 19:45:06 2012 +0000 @@ -1,4 +1,4 @@ -## Copyright (C) 2009 Lukas F. Reichlin +## Copyright (C) 2009, 2012 Lukas F. Reichlin ## ## This file is part of LTI Syncope. ## @@ -21,37 +21,32 @@ ## Author: Lukas Reichlin <lukas.reichlin@gmail.com> ## Created: September 2009 -## Version: 0.2 +## Version: 0.3 function a = subsref (a, s) - if (isempty (s)) - error ("lti: subsref: missing index"); + if (numel (s) == 0) + return; endif - for k = 1 : numel (s) - if (isa (a, "lti")) - switch (s(k).type) - case "()" - idx = s(k).subs; - if (numel (idx) == 2) - a = __sys_prune__ (a, idx{1}, idx{2}); - elseif (numel (idx) == 1) - a = __freqresp__ (a, idx{1}); - else - error ("lti: subsref: need one or two indices"); - endif - case "." - fld = s(k).subs; - a = get (a, fld); - ## warning ("lti: subsref: do not use subsref for development"); - otherwise - error ("lti: subsref: invalid subscript type"); - endswitch - else # not an LTI model - a = subsref (a, s(k:end)); - return; - endif - endfor + switch (s(1).type) + case "()" + idx = s(1).subs; + if (numel (idx) == 2) + a = __sys_prune__ (a, idx{1}, idx{2}); + elseif (numel (idx) == 1) + a = __freqresp__ (a, idx{1}); + else + error ("lti: subsref: need one or two indices"); + endif + case "." + fld = s(1).subs; + a = get (a, fld); + ## warning ("lti: subsref: do not use subsref for development"); + otherwise + error ("lti: subsref: invalid subscript type"); + endswitch + + a = subsref (a, s(2:end)); -endfunction \ No newline at end of file +endfunction