3430
|
1 ## Copyright (C) 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 -*- |
|
20 ## @deftypefn {Function File} {[@var{stname}, @var{inname}, @var{outname}, @var{yd}] =} sysgetsignals (@var{sys}) |
|
21 ## @deftypefnx{Function File} {@var{siglist} =} sysgetsignals (@var{sys},@var{sigid}) |
|
22 ## @deftypefnx{Function File} {@var{signame} =} sysgetsignals (@var{sys},@var{sigid},@var{signum}@{, @var{strflg}@}) |
|
23 ## Get signal names from a system |
|
24 ## |
|
25 ## @strong{Inputs} |
|
26 ## @table @var |
|
27 ## @item sys |
|
28 ## system data structure for the state space system |
|
29 ## |
|
30 ## @item sigid |
|
31 ## signal id. String. Must be one of |
|
32 ## @table @code |
|
33 ## @item "in" |
|
34 ## input signals |
|
35 ## @item "out" |
|
36 ## output signals |
|
37 ## @item "st" |
|
38 ## stage signals |
|
39 ## @item "yd" |
|
40 ## value of logical vector @var{yd} |
|
41 ## @end table |
|
42 ## |
|
43 ## @item signum |
|
44 ## Index of signal (or indices of signals if signum is a vector) |
|
45 ## |
|
46 ## @item strflg |
|
47 ## flag to return a string instead of a list; Values: |
|
48 ## @table @code |
|
49 ## @item 0 |
|
50 ## (default) return a list (even if signum is a scalar) |
|
51 ## |
|
52 ## @item 1 |
|
53 ## return a string. Exits with an error if signum is not a scalar. |
|
54 ## @end table |
|
55 ## |
|
56 ## @end table |
|
57 ## |
|
58 ## @strong{Outputs} |
|
59 ## @table @bullet |
|
60 ## @item If @var{sigid} is not specified |
|
61 ## @table @var |
|
62 ## @item stname |
|
63 ## @itemx inname |
|
64 ## @itemx outname |
|
65 ## signal names (lists of strings); names of states, |
|
66 ## inputs, and outputs, respectively |
|
67 ## @item yd |
|
68 ## binary vector; @var{yd}(@var{ii}) is nonzero if output @var{ii} is |
|
69 ## discrete. |
|
70 ## @end table |
|
71 ## |
|
72 ## @item If @var{sigid} is specified but @var{signum} is not specified, then |
|
73 ## @table @code |
|
74 ## @item sigid="in" |
|
75 ## @var{siglist} is set to the list of input names |
|
76 ## |
|
77 ## @item sigid="out" |
|
78 ## @var{siglist} is set to the list of output names |
|
79 ## |
|
80 ## @item sigid="st" |
|
81 ## @var{siglist} is set to the list of state names |
|
82 ## |
|
83 ## stage signals |
|
84 ## @item sigid="yd" |
|
85 ## @var{siglist} is set to logical vector indicating discrete outputs; |
3439
|
86 ## @var{siglist}(@var{ii}) = 0 indicates that output @var{ii} is continuous |
3430
|
87 ## (unsampled), otherwise it is discrete. |
|
88 ## |
|
89 ## @end table |
|
90 ## |
|
91 ## @item if the first three input arguments are specified, then @var{signame} is |
|
92 ## a list of the specified signal names (@var{sigid} is @code{"in"}, |
|
93 ## @code{"out"}, or @code{"st"}), or else the logical flag |
|
94 ## indicating whether output(s) @var{signum} is(are) discrete (@var{sigval}=1) |
|
95 ## or continuous (@var{sigval}=0). |
|
96 ## @end table |
|
97 ## |
|
98 ## @strong{Examples} (From @code{sysrepdemo}) |
|
99 ## @example |
|
100 ## octave> sys=ss2sys(rand(4),rand(4,2),rand(3,4)); |
|
101 ## octave> [Ast,Ain,Aout,Ayd] = sysgetsignals(sys) i # get all signal names |
|
102 ## Ast = |
|
103 ## ( |
|
104 ## [1] = x_1 |
|
105 ## [2] = x_2 |
|
106 ## [3] = x_3 |
|
107 ## [4] = x_4 |
|
108 ## ) |
|
109 ## Ain = |
|
110 ## ( |
|
111 ## [1] = u_1 |
|
112 ## [2] = u_2 |
|
113 ## ) |
|
114 ## Aout = |
|
115 ## ( |
|
116 ## [1] = y_1 |
|
117 ## [2] = y_2 |
|
118 ## [3] = y_3 |
|
119 ## ) |
|
120 ## Ayd = |
|
121 ## |
|
122 ## 0 0 0 |
|
123 ## octave> Ain = sysgetsignals(sys,"in") # get only input signal names |
|
124 ## Ain = |
|
125 ## ( |
|
126 ## [1] = u_1 |
|
127 ## [2] = u_2 |
|
128 ## ) |
|
129 ## octave> Aout = sysgetsignals(sys,"out",2) # get name of output 2 (in list) |
|
130 ## Aout = |
|
131 ## ( |
|
132 ## [1] = y_2 |
|
133 ## ) |
|
134 ## octave> Aout = sysgetsignals(sys,"out",2,1) # get name of output 2 (as string) |
|
135 ## Aout = y_2 |
|
136 ## @end example |
|
137 ## @end deftypefn |
|
138 |
|
139 function [stname, inname, outname, yd] = sysgetsignals (sys, sigid, signum, strflg) |
|
140 |
|
141 ## Adapted from ss2sys |
|
142 |
|
143 if(nargin < 1 | nargin > 4 | nargout > 4) |
|
144 usage("[stname{,inname,outname,yd}] = sysgetsignals(sys{,sigid,signum})") |
|
145 elseif(nargin > 1 & nargout > 1) |
|
146 usage("sig = sysgetsignals(sys,sigid{,signum,strflg})") |
|
147 elseif( ! is_struct(sys) ) |
|
148 error("input argument must be a system data structure"); |
|
149 endif |
|
150 if(nargin < 4) strflg = 0; endif |
|
151 if(nargin == 1) |
|
152 sys = sysupdate(sys,"ss"); #make sure ss is up to date |
|
153 stname = sysgetsignals(sys,"st"); |
|
154 inname = sysgetsignals(sys,"in"); |
|
155 outname = sysgetsignals(sys,"out"); |
|
156 yd = sysgetsignals(sys,"yd"); |
|
157 elseif(!(isstr(sigid) & min(size(sigid)) == 1)) |
|
158 error(sprintf("sigid(%dx%d) must be a string)",rows(sigid),columns(sigid))); |
|
159 else |
|
160 if(strcmp("st",sigid)) stname = sys.stname; |
|
161 elseif(strcmp("in",sigid)) stname = sys.inname; |
|
162 elseif(strcmp("out",sigid)) stname = sys.outname; |
|
163 elseif(strcmp("yd",sigid)) stname = vec(sys.yd)'; |
|
164 else |
|
165 error(sprintf("sigid=%s must be \"st\", \"in\", \"out\", or \"yd\"", ... |
|
166 sigid)); |
|
167 endif |
|
168 if(nargin >= 3) |
|
169 if(signum > length(stname)) |
|
170 error(sprintf("sysgetsignals(sys,\"%s\",%d):only %d entries.\n", ... |
|
171 sigid,signum, rows(stname))); |
|
172 else |
|
173 if(!is_scalar(strflg)) |
|
174 error("strflg must be a scalar"); |
|
175 endif |
|
176 switch(strflg) |
|
177 case(0), |
|
178 stname = stname(signum); |
|
179 case(1), |
|
180 if(length(signum) > 1) |
|
181 error("strflg=1, length(signum) = %d",length(signum)); |
|
182 endif |
|
183 stname = nth(stname,signum); |
|
184 otherwise, |
|
185 error ("invalid value of strflg = %e", strflg); |
|
186 endswitch |
|
187 |
|
188 endif |
|
189 endif |
|
190 endif |
|
191 |
|
192 endfunction |
|
193 |