7017
|
1 ## Copyright (C) 1998, 2000, 2002, 2004, 2005, 2006, 2007 |
|
2 ## Auburn University. All rights reserved. |
3430
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
7 ## under the terms of the GNU General Public License as published by |
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
3430
|
10 ## |
7016
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
3430
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
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 |
7133
|
149 if (nargin < 1 || nargin > 4) |
6046
|
150 print_usage (); |
7135
|
151 elseif (! isstruct (sys)) |
|
152 error ("input argument must be a system data structure"); |
|
153 endif |
|
154 if (nargin < 4) |
|
155 strflg = 0; |
3430
|
156 endif |
7135
|
157 |
|
158 if (nargin == 1) |
|
159 sys = sysupdate (sys, "ss"); #make sure ss is up to date |
|
160 stname = sysgetsignals (sys, "st"); |
|
161 inname = sysgetsignals (sys, "in"); |
|
162 outname = sysgetsignals (sys, "out"); |
|
163 yd = sysgetsignals (sys, "yd"); |
|
164 elseif (! (ischar (sigid) && min (size (sigid)) == 1)) |
|
165 error ("sigid(%dx%d) must be a string)", rows (sigid), columns (sigid)); |
3430
|
166 else |
7135
|
167 if (strcmp ("st", sigid)) |
|
168 stname = sys.stname; |
|
169 elseif (strcmp ("in", sigid)) |
|
170 stname = sys.inname; |
|
171 elseif (strcmp ("out", sigid)) |
|
172 stname = sys.outname; |
|
173 elseif (strcmp ("yd", sigid)) |
|
174 stname = vec(sys.yd)'; |
3430
|
175 else |
7135
|
176 error ("sigid=%s must be \"st\", \"in\", \"out\", or \"yd\"", sigid); |
3430
|
177 endif |
7135
|
178 if (nargin >= 3) |
|
179 if (is_signal_list (signum) || ischar (signum)) |
|
180 signum = cellidx (stname, signum); |
|
181 endif |
|
182 if (max (signum) > length (stname)) |
|
183 error ("sysgetsignals(sys,\"%s\",%d):only %d entries", |
|
184 sigid, signum, rows (stname)); |
3430
|
185 else |
7135
|
186 if (! isscalar (strflg)) |
|
187 error ("strflg must be a scalar"); |
3430
|
188 endif |
7135
|
189 switch (strflg) |
|
190 case 0 |
|
191 stname = stname (signum); |
|
192 case 1 |
|
193 if (length (signum) > 1) |
|
194 error ("strflg=1, length(signum) = %d", length (signum)); |
3430
|
195 endif |
4771
|
196 stname = stname{signum}; |
7135
|
197 otherwise |
3430
|
198 error ("invalid value of strflg = %e", strflg); |
|
199 endswitch |
|
200 endif |
|
201 endif |
|
202 endif |
|
203 |
|
204 endfunction |
|
205 |