3430
|
1 ## Copyright (C) 1996, 1998 Auburn University. All rights reserved. |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by the |
|
7 ## Free Software Foundation; either version 2, or (at your option) any |
|
8 ## later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 ## for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
|
18 |
|
19 ## -*- texinfo -*- |
3500
|
20 ## @deftypefn {Function File} {[@var{n}, @var{nz}, @var{m}, @var{p}, @var{yd}] =} sysdimensions (@var{sys}, @var{opt}) |
3430
|
21 ## return the number of states, inputs, and/or outputs in the system |
|
22 ## @var{sys}. |
|
23 ## |
|
24 ## @strong{Inputs} |
|
25 ## @table @var |
|
26 ## @item sys |
|
27 ## system data structure |
|
28 ## |
|
29 ## @item opt |
|
30 ## String indicating which dimensions are desired. Values: |
|
31 ## @table @code |
|
32 ## @item "all" |
|
33 ## (default) return all parameters as specified under Outputs below. |
|
34 ## |
|
35 ## @item "cst" |
|
36 ## return @var{n}= number of continuous states |
|
37 ## |
|
38 ## @item "dst" |
|
39 ## return @var{n}= number of discrete states |
|
40 ## |
|
41 ## @item "in" |
|
42 ## return @var{n}= number of inputs |
|
43 ## |
|
44 ## @item "out" |
|
45 ## return @var{n}= number of outputs |
|
46 ## @end table |
|
47 ## @end table |
|
48 ## |
|
49 ## @strong{Outputs} |
|
50 ## @table @var |
|
51 ## @item n |
|
52 ## number of continuous states (or individual requested dimension as specified |
|
53 ## by @var{opt}). |
|
54 ## @item nz |
|
55 ## number of discrete states |
|
56 ## @item m |
|
57 ## number of system inputs |
|
58 ## @item p |
|
59 ## number of system outputs |
|
60 ## @item yd |
|
61 ## binary vector; @var{yd}(@var{ii}) is nonzero if output @var{ii} is |
|
62 ## discrete. |
|
63 ## @math{yd(ii) = 0} if output @var{ii} is continous |
|
64 ## @end table |
|
65 ## @end deftypefn |
|
66 ## @seealso{sysgetsignals and sysgettsam} |
|
67 |
|
68 function [n, nz, m, p, yd] = sysdimensions (sys, opt) |
|
69 |
|
70 if(nargout > 5 | nargin < 1 | nargin > 2) |
|
71 usage("[n,nz,m,p[,yd]] = sysdimensions(sys{,opt})"); |
4030
|
72 elseif(!isstruct(sys)) |
3430
|
73 usage("[n,nz,m,p] = sysdimensions(sys)"); |
|
74 elseif(nargin == 1) |
|
75 opt = "all"; |
|
76 endif |
|
77 |
|
78 n = sys.n; |
|
79 nz = sys.nz; |
|
80 m = length(sysgetsignals(sys,"in")); |
|
81 p = length(sysgetsignals(sys,"out")); |
|
82 yd = sys.yd; |
|
83 valid_options = list("all","cst","dst","st","in","out"); |
|
84 valid_values = list(n,n,nz,n+nz,m,p); |
|
85 |
|
86 valid_opt = 0; |
|
87 for ii=1:length(valid_options) |
|
88 if(strcmp(nth(valid_options,ii),opt)) |
|
89 n = nth(valid_values,ii); |
|
90 valid_opt = 1; |
|
91 if(ii > 1 & nargout > 1) |
|
92 warning("opt=%s, %d output arguments requested",opt,nargout); |
|
93 endif |
|
94 endif |
|
95 endfor |
|
96 |
|
97 if (! valid_opt) |
|
98 error ("invalid option passed = %s", opt); |
|
99 endif |
|
100 |
|
101 endfunction |