]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@lti/subsref.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @lti / subsref.m
1 ## Copyright (C) 2009, 2012   Lukas F. Reichlin
2 ##
3 ## This file is part of LTI Syncope.
4 ##
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
9 ##
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.
17
18 ## -*- texinfo -*-
19 ## Subscripted reference for LTI objects.
20 ## Used by Octave for "sys = sys(2:4, :)" or "val = sys.prop".
21
22 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
23 ## Created: September 2009
24 ## Version: 0.4
25
26 function a = subsref (a, s)
27
28   if (numel (s) == 0)
29     return;
30   endif
31
32   switch (s(1).type)
33     case "()"
34       idx = s(1).subs;
35       if (numel (idx) == 2)
36         a = __sys_prune__ (a, idx{1}, idx{2});
37       elseif (numel (idx) == 1)
38         a = __freqresp__ (a, idx{1});  
39       else
40         error ("lti: subsref: need one or two indices");
41       endif
42     case "."
43       fld = s(1).subs;
44       a = get (a, fld);
45       ## warning ("lti: subsref: do not use subsref for development");
46     otherwise
47       error ("lti: subsref: invalid subscript type");
48   endswitch
49   
50   a = subsref (a, s(2:end));
51
52 endfunction
53
54
55 ## lti: subsref
56 %!shared a
57 %! s = tf ("s");
58 %! G = (s+1)*s*5/(s+1)/(s^2+s+1);
59 %! a = G(1,1).num{1,1}(1);
60 %!assert (a, 5, 1e-4);