From: <par...@us...> - 2010-08-30 01:09:28
|
Revision: 7604 http://octave.svn.sourceforge.net/octave/?rev=7604&view=rev Author: paramaniac Date: 2010-08-30 01:09:22 +0000 (Mon, 30 Aug 2010) Log Message: ----------- control: add nested subsref (stuff like sys(1,1).num{1,1}(1)) and tests Modified Paths: -------------- trunk/octave-forge/main/control/inst/@lti/subsref.m trunk/octave-forge/main/control/inst/ltimodels.m Modified: trunk/octave-forge/main/control/inst/@lti/subsref.m =================================================================== --- trunk/octave-forge/main/control/inst/@lti/subsref.m 2010-08-29 23:49:31 UTC (rev 7603) +++ trunk/octave-forge/main/control/inst/@lti/subsref.m 2010-08-30 01:09:22 UTC (rev 7604) @@ -21,33 +21,37 @@ ## Author: Lukas Reichlin <luk...@gm...> ## Created: September 2009 -## Version: 0.1 +## Version: 0.2 -function ret = subsref (sys, s) +function a = subsref (a, s) if (isempty (s)) error ("lti: subsref: missing index"); endif - switch (s(1).type) - case "()" - idx = s(1).subs; - if (numel (idx) == 2) - ret = __sysprune__ (sys, idx{1}, idx{2}); - elseif (numel (idx) == 1) - ret = __freqresp__ (sys, idx{1}); - else - error ("lti: subsref: need one or two indices"); - endif + for k = 1 : numel (s) + if (isa (a, "lti")) + switch (s(k).type) + case "()" + idx = s(k).subs; + if (numel (idx) == 2) + a = __sysprune__ (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 - case "." - fld = s.subs; - ret = get (sys, fld); - ## warning ("lti: subsref: do not use subsref for development"); - - otherwise - error ("lti: subsref: invalid subscript type"); - - endswitch - endfunction \ No newline at end of file Modified: trunk/octave-forge/main/control/inst/ltimodels.m =================================================================== --- trunk/octave-forge/main/control/inst/ltimodels.m 2010-08-29 23:49:31 UTC (rev 7603) +++ trunk/octave-forge/main/control/inst/ltimodels.m 2010-08-30 01:09:22 UTC (rev 7604) @@ -222,3 +222,25 @@ %!assert (C.c, D.c); %!assert (C.d, D.d); +## tf: minreal +%!shared a, b, c, d +%! s = tf ("s"); +%! G1 = (s+1)*s*5/(s+1)/(s^2+s+1); +%! G2 = tf ([1, 1, 1], [2, 2, 2]); +%! G1min = minreal (G1); +%! G2min = minreal (G2); +%! a = G1min.num{1, 1}; +%! b = G1min.den{1, 1}; +%! c = G2min.num{1, 1}; +%! d = G2min.den{1, 1}; +%!assert (a, [5, 0], 1e-4); +%!assert (b, [1, 1, 1], 1e-4); +%!assert (c, 0.5, 1e-4); +%!assert (d, 1, 1e-4); + +## lti: subsref +%!shared a +%! s = tf ("s"); +%! G = (s+1)*s*5/(s+1)/(s^2+s+1); +%! a = G(1,1).num{1,1}(1); +%!assert (a, 5, 1e-4); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |