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