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