comparison scripts/control/sysdimensions.m @ 3228:dbcc24961c44

[project @ 1998-12-09 18:42:12 by jwe]
author jwe
date Wed, 09 Dec 1998 18:42:13 +0000
parents ba1c7cdc6090
children 2e74d8aa1a20
comparison
equal deleted inserted replaced
3227:e090571062ee 3228:dbcc24961c44
14 # 14 #
15 # You should have received a copy of the GNU General Public License 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 16 # along with Octave; see the file COPYING. If not, write to the Free
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 18
19 function [n,nz,m,p,yd] = sysdimensions(sys) 19 function [n,nz,m,p,yd] = sysdimensions(sys,opt)
20 # [n,nz,m,p[,yd]] = sysdimensions(sys) 20 # [n,nz,m,p,yd] = sysdimensions(sys{,opt})
21 # return the number of states, inputs, and outputs in the system sys. 21 # return the number of states, inputs, and/or outputs in the system sys.
22 # inputs: sys: system data structure 22 # inputs: sys: system data structure
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
27 # "in": return n=number of inputs
28 # "out": return n = number of outputs
23 # outputs: 29 # outputs:
24 # n: number of continuous states 30 # n: number of continuous states (or the specified dimension as shown above)
25 # nz: number of discrete states 31 # nz: number of discrete states
26 # m: number of system inputs 32 # m: number of system inputs
27 # p: number of system outputs 33 # p: number of system outputs
28 # yd: is the discrete output vector: yd(ii) = 1 if output ii is sampled, 34 # yd: is the discrete output vector: yd(ii) = 1 if output ii is sampled,
29 # yd(ii) = 0 if output ii is continous 35 # yd(ii) = 0 if output ii is continous
30 # 36 #
31 # see also: sysgetsignals, sysgettsam 37 # see also: sysgetsignals, sysgettsam
32 38
33 if(nargout > 5 | nargin != 1) 39 if(nargout > 5 | nargin < 1 | nargin > 2)
34 usage("[n,nz,m,p[,yd]] = sysdimensions(sys)"); 40 usage("[n,nz,m,p[,yd]] = sysdimensions(sys{,opt})");
35 elseif(!is_struct(sys)) 41 elseif(!is_struct(sys))
36 usage("[n,nz,m,p] = sysdimensions(sys)"); 42 usage("[n,nz,m,p] = sysdimensions(sys)");
43 elseif(nargin == 1)
44 opt = "all";
37 endif 45 endif
38 46
39 n = sys.n; 47 n = sys.n;
40 nz = sys.nz; 48 nz = sys.nz;
41 m = rows(sys.inname); 49 m = length(sysgetsignals(sys,"in"));
42 p = rows(sys.outname); 50 p = length(sysgetsignals(sys,"out"));
43 yd = sys.yd; 51 yd = sys.yd;
52 legal_options = list("all","cst","dst","in","out");
53 legal_values = list(n,n,nz,m,p);
54
55 for ii=1:length(legal_options)
56 if(strcmp(nth(legal_options,ii),opt))
57 n = nth(legal_values,ii);
58 if(ii > 1 & nargout > 1)
59 warning("opt=%s, %d output arguments requested",opt,nargout);
60 endif
61 endif
62 endfor
44 63
45 endfunction 64 endfunction