]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@lti/size.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @lti / size.m
1 ## Copyright (C) 2009, 2011   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 ## @deftypefn {Function File} {@var{nvec} =} size (@var{sys})
20 ## @deftypefnx {Function File} {@var{n} =} size (@var{sys}, @var{dim})
21 ## @deftypefnx {Function File} {[@var{p}, @var{m}] =} size (@var{sys})
22 ## LTI model size, i.e. number of outputs and inputs.
23 ##
24 ## @strong{Inputs}
25 ## @table @var
26 ## @item sys
27 ## LTI system.
28 ## @item dim
29 ## If given a second argument, @command{size} will return the size of the
30 ## corresponding dimension.
31 ## @end table
32 ##
33 ## @strong{Outputs}
34 ## @table @var
35 ## @item nvec
36 ## Row vector.  The first element is the number of outputs (rows) and the second
37 ## element the number of inputs (columns).
38 ## @item n
39 ## Scalar value.  The size of the dimension @var{dim}.
40 ## @item p
41 ## Number of outputs.
42 ## @item m
43 ## Number of inputs.
44 ## @end table
45 ## @end deftypefn
46
47 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
48 ## Created: September 2009
49 ## Version: 0.2
50
51 function [n, varargout] = size (sys, dim = 0)
52
53   if (nargin > 2)
54     print_usage ();
55   endif
56
57   p = numel (sys.outname);  # WARNING: system matrices may change without
58   m = numel (sys.inname);   #          being noticed by the i/o names!
59
60   switch (dim)
61     case 0
62       switch (nargout)
63         case 0
64           if (p == 1)
65             stry = "";
66           else
67             stry = "s";
68           endif          
69           if (m == 1)
70             stru = "";
71           else
72             stru = "s";
73           endif
74           disp (sprintf ("LTI model with %d output%s and %d input%s.", p, stry, m, stru));
75         case 1
76           n = [p, m];
77         case 2
78           n = p;
79           varargout{1} = m;
80         otherwise
81           print_usage ();
82       endswitch
83     case 1
84       n = p;
85     case 2
86       n = m;
87     otherwise
88       print_usage ();
89   endswitch
90
91 endfunction