3213
|
1 # Copyright (C) 1996,1998 A. Scottedward Hodel |
|
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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
3228
|
19 function [n,nz,m,p,yd] = sysdimensions(sys,opt) |
|
20 # [n,nz,m,p,yd] = sysdimensions(sys{,opt}) |
|
21 # return the number of states, inputs, and/or outputs in the system sys. |
3213
|
22 # inputs: sys: system data structure |
3228
|
23 # opt: string |
|
24 # "all" (default): return all output arguments (see below) |
|
25 # "cst": return n=number of continuous states |
|
26 # "dst": return n=number of discrete states |
3240
|
27 # "st": return n=number of states (continuous and discrete) |
3228
|
28 # "in": return n=number of inputs |
3240
|
29 # "out": return n=number of outputs |
3213
|
30 # outputs: |
3228
|
31 # n: number of continuous states (or the specified dimension as shown above) |
3213
|
32 # nz: number of discrete states |
|
33 # m: number of system inputs |
|
34 # p: number of system outputs |
|
35 # yd: is the discrete output vector: yd(ii) = 1 if output ii is sampled, |
|
36 # yd(ii) = 0 if output ii is continous |
|
37 # |
|
38 # see also: sysgetsignals, sysgettsam |
|
39 |
3228
|
40 if(nargout > 5 | nargin < 1 | nargin > 2) |
|
41 usage("[n,nz,m,p[,yd]] = sysdimensions(sys{,opt})"); |
3213
|
42 elseif(!is_struct(sys)) |
|
43 usage("[n,nz,m,p] = sysdimensions(sys)"); |
3228
|
44 elseif(nargin == 1) |
|
45 opt = "all"; |
3213
|
46 endif |
|
47 |
|
48 n = sys.n; |
|
49 nz = sys.nz; |
3228
|
50 m = length(sysgetsignals(sys,"in")); |
|
51 p = length(sysgetsignals(sys,"out")); |
3213
|
52 yd = sys.yd; |
3240
|
53 legal_options = list("all","cst","dst","st","in","out"); |
|
54 legal_values = list(n,n,nz,n+nz,m,p); |
3228
|
55 |
3240
|
56 legal_opt = 0; |
3228
|
57 for ii=1:length(legal_options) |
|
58 if(strcmp(nth(legal_options,ii),opt)) |
|
59 n = nth(legal_values,ii); |
3240
|
60 legal_opt = 1; |
3228
|
61 if(ii > 1 & nargout > 1) |
|
62 warning("opt=%s, %d output arguments requested",opt,nargout); |
|
63 endif |
|
64 endif |
|
65 endfor |
3240
|
66 if(!legal_opt) |
|
67 error("illegal option passed = %s",opt); |
|
68 endif |
3213
|
69 |
|
70 endfunction |