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