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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301 USA. |
3430
|
19 |
|
20 ## -*- texinfo -*- |
3500
|
21 ## @deftypefn {Function File} {[@var{n}, @var{nz}, @var{m}, @var{p}, @var{yd}] =} sysdimensions (@var{sys}, @var{opt}) |
3430
|
22 ## return the number of states, inputs, and/or outputs in the system |
|
23 ## @var{sys}. |
|
24 ## |
|
25 ## @strong{Inputs} |
|
26 ## @table @var |
|
27 ## @item sys |
|
28 ## system data structure |
|
29 ## |
|
30 ## @item opt |
|
31 ## String indicating which dimensions are desired. Values: |
|
32 ## @table @code |
|
33 ## @item "all" |
|
34 ## (default) return all parameters as specified under Outputs below. |
|
35 ## |
|
36 ## @item "cst" |
|
37 ## return @var{n}= number of continuous states |
|
38 ## |
|
39 ## @item "dst" |
|
40 ## return @var{n}= number of discrete states |
|
41 ## |
|
42 ## @item "in" |
|
43 ## return @var{n}= number of inputs |
|
44 ## |
|
45 ## @item "out" |
|
46 ## return @var{n}= number of outputs |
|
47 ## @end table |
|
48 ## @end table |
|
49 ## |
|
50 ## @strong{Outputs} |
|
51 ## @table @var |
|
52 ## @item n |
|
53 ## number of continuous states (or individual requested dimension as specified |
|
54 ## by @var{opt}). |
|
55 ## @item nz |
|
56 ## number of discrete states |
|
57 ## @item m |
|
58 ## number of system inputs |
|
59 ## @item p |
|
60 ## number of system outputs |
|
61 ## @item yd |
|
62 ## binary vector; @var{yd}(@var{ii}) is nonzero if output @var{ii} is |
|
63 ## discrete. |
|
64 ## @math{yd(ii) = 0} if output @var{ii} is continous |
|
65 ## @end table |
5642
|
66 ## @seealso{sysgetsignals, sysgettsam} |
3430
|
67 ## @end deftypefn |
|
68 |
|
69 function [n, nz, m, p, yd] = sysdimensions (sys, opt) |
|
70 |
|
71 if(nargout > 5 | nargin < 1 | nargin > 2) |
|
72 usage("[n,nz,m,p[,yd]] = sysdimensions(sys{,opt})"); |
4030
|
73 elseif(!isstruct(sys)) |
3430
|
74 usage("[n,nz,m,p] = sysdimensions(sys)"); |
|
75 elseif(nargin == 1) |
|
76 opt = "all"; |
|
77 endif |
|
78 |
|
79 n = sys.n; |
|
80 nz = sys.nz; |
|
81 m = length(sysgetsignals(sys,"in")); |
|
82 p = length(sysgetsignals(sys,"out")); |
|
83 yd = sys.yd; |
4771
|
84 valid_options = {"all","cst","dst","st","in","out"}; |
|
85 valid_values = {n,n,nz,n+nz,m,p}; |
3430
|
86 |
|
87 valid_opt = 0; |
|
88 for ii=1:length(valid_options) |
4771
|
89 if(strcmp(valid_options{ii},opt)) |
|
90 n = valid_values{ii}; |
3430
|
91 valid_opt = 1; |
|
92 if(ii > 1 & nargout > 1) |
|
93 warning("opt=%s, %d output arguments requested",opt,nargout); |
|
94 endif |
|
95 endif |
|
96 endfor |
|
97 |
|
98 if (! valid_opt) |
|
99 error ("invalid option passed = %s", opt); |
|
100 endif |
|
101 |
|
102 endfunction |