# HG changeset patch # User paramaniac # Date 1331408706 0 # Node ID 40a1e6b3672660f6d888621578fce41f940c7770 # Parent cdf1dbf20cd46cfce8a7c8e961be271bb4638fab control: use recursion instead of for-loop for subs ref diff -r cdf1dbf20cd4 -r 40a1e6b36726 main/control/inst/@lti/subsref.m --- 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 ## 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