comparison scripts/control/system/sysgetsignals.m @ 4771:b8105302cfe8

[project @ 2004-02-16 17:45:50 by jwe]
author jwe
date Mon, 16 Feb 2004 17:45:50 +0000
parents 22bd65326ec1
children bdbee5282954
comparison
equal deleted inserted replaced
4770:ef5e598f099b 4771:b8105302cfe8
42 ## 42 ##
43 ## @item signum 43 ## @item signum
44 ## index(indices) or name(s) or signals; see @code{sysidx} 44 ## index(indices) or name(s) or signals; see @code{sysidx}
45 ## 45 ##
46 ## @item strflg 46 ## @item strflg
47 ## flag to return a string instead of a list; Values: 47 ## flag to return a string instead of a cell array; Values:
48 ## @table @code 48 ## @table @code
49 ## @item 0 49 ## @item 0
50 ## (default) return a list (even if signum specifies an individual signal) 50 ## (default) return a cell array (even if signum specifies an individual signal)
51 ## 51 ##
52 ## @item 1 52 ## @item 1
53 ## return a string. Exits with an error if signum does not specify an 53 ## return a string. Exits with an error if signum does not specify an
54 ## individual signal. 54 ## individual signal.
55 ## @end table 55 ## @end table
61 ## @item If @var{sigid} is not specified 61 ## @item If @var{sigid} is not specified
62 ## @table @var 62 ## @table @var
63 ## @item stname 63 ## @item stname
64 ## @itemx inname 64 ## @itemx inname
65 ## @itemx outname 65 ## @itemx outname
66 ## signal names (lists of strings); names of states, 66 ## signal names (cell array of strings); names of states,
67 ## inputs, and outputs, respectively 67 ## inputs, and outputs, respectively
68 ## @item yd 68 ## @item yd
69 ## binary vector; @var{yd}(@var{ii}) is nonzero if output @var{ii} is 69 ## binary vector; @var{yd}(@var{ii}) is nonzero if output @var{ii} is
70 ## discrete. 70 ## discrete.
71 ## @end table 71 ## @end table
72 ## 72 ##
73 ## @item If @var{sigid} is specified but @var{signum} is not specified, then 73 ## @item If @var{sigid} is specified but @var{signum} is not specified, then
74 ## @table @code 74 ## @table @code
75 ## @item sigid="in" 75 ## @item sigid="in"
76 ## @var{siglist} is set to the list of input names 76 ## @var{siglist} is set to the cell array of input names
77 ## 77 ##
78 ## @item sigid="out" 78 ## @item sigid="out"
79 ## @var{siglist} is set to the list of output names 79 ## @var{siglist} is set to the cell array of output names
80 ## 80 ##
81 ## @item sigid="st" 81 ## @item sigid="st"
82 ## @var{siglist} is set to the list of state names 82 ## @var{siglist} is set to the cell array of state names
83 ## 83 ##
84 ## stage signals 84 ## stage signals
85 ## @item sigid="yd" 85 ## @item sigid="yd"
86 ## @var{siglist} is set to logical vector indicating discrete outputs; 86 ## @var{siglist} is set to logical vector indicating discrete outputs;
87 ## @var{siglist}(@var{ii}) = 0 indicates that output @var{ii} is continuous 87 ## @var{siglist}(@var{ii}) = 0 indicates that output @var{ii} is continuous
88 ## (unsampled), otherwise it is discrete. 88 ## (unsampled), otherwise it is discrete.
89 ## 89 ##
90 ## @end table 90 ## @end table
91 ## 91 ##
92 ## @item if the first three input arguments are specified, then @var{signame} is 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"}, 93 ## a cell array of the specified signal names (@var{sigid} is @code{"in"},
94 ## @code{"out"}, or @code{"st"}), or else the logical flag 94 ## @code{"out"}, or @code{"st"}), or else the logical flag
95 ## indicating whether output(s) @var{signum} is(are) discrete (@var{sigval}=1) 95 ## indicating whether output(s) @var{signum} is(are) discrete (@var{sigval}=1)
96 ## or continuous (@var{sigval}=0). 96 ## or continuous (@var{sigval}=0).
97 ## @end table 97 ## @end table
98 ## 98 ##
99 ## @strong{Examples} (From @code{sysrepdemo}) 99 ## @strong{Examples} (From @code{sysrepdemo})
100 ## @example 100 ## @example
101 ## octave> sys=ss2sys(rand(4),rand(4,2),rand(3,4)); 101 ## octave> sys=ss(rand(4),rand(4,2),rand(3,4));
102 ## octave> [Ast,Ain,Aout,Ayd] = sysgetsignals(sys) i # get all signal names 102 ## octave> [Ast,Ain,Aout,Ayd] = sysgetsignals(sys) i # get all signal names
103 ## Ast = 103 ## Ast =
104 ## ( 104 ## (
105 ## [1] = x_1 105 ## [1] = x_1
106 ## [2] = x_2 106 ## [2] = x_2
125 ## Ain = 125 ## Ain =
126 ## ( 126 ## (
127 ## [1] = u_1 127 ## [1] = u_1
128 ## [2] = u_2 128 ## [2] = u_2
129 ## ) 129 ## )
130 ## octave> Aout = sysgetsignals(sys,"out",2) # get name of output 2 (in list) 130 ## octave> Aout = sysgetsignals(sys,"out",2) # get name of output 2 (in cell array)
131 ## Aout = 131 ## Aout =
132 ## ( 132 ## (
133 ## [1] = y_2 133 ## [1] = y_2
134 ## ) 134 ## )
135 ## octave> Aout = sysgetsignals(sys,"out",2,1) # get name of output 2 (as string) 135 ## octave> Aout = sysgetsignals(sys,"out",2,1) # get name of output 2 (as string)
137 ## @end example 137 ## @end example
138 ## @end deftypefn 138 ## @end deftypefn
139 139
140 function [stname, inname, outname, yd] = sysgetsignals (sys, sigid, signum, strflg) 140 function [stname, inname, outname, yd] = sysgetsignals (sys, sigid, signum, strflg)
141 141
142 ## Adapted from ss2sys 142 ## Adapted from ss
143 143
144 if(nargin < 1 | nargin > 4 | nargout > 4) 144 if(nargin < 1 | nargin > 4 | nargout > 4)
145 usage("[stname{,inname,outname,yd}] = sysgetsignals(sys{,sigid,signum})") 145 usage("[stname{,inname,outname,yd}] = sysgetsignals(sys{,sigid,signum})")
146 elseif(nargin > 1 & nargout > 1) 146 elseif(nargin > 1 & nargout > 1)
147 usage("sig = sysgetsignals(sys,sigid{,signum,strflg})") 147 usage("sig = sysgetsignals(sys,sigid{,signum,strflg})")
166 error(sprintf("sigid=%s must be \"st\", \"in\", \"out\", or \"yd\"", ... 166 error(sprintf("sigid=%s must be \"st\", \"in\", \"out\", or \"yd\"", ...
167 sigid)); 167 sigid));
168 endif 168 endif
169 if(nargin >= 3) 169 if(nargin >= 3)
170 if( is_signal_list(signum) | isstr(signum) ) 170 if( is_signal_list(signum) | isstr(signum) )
171 signum = listidx(stname,signum); 171 signum = cellidx(stname,signum);
172 end 172 end
173 if(max(signum) > length(stname)) 173 if(max(signum) > length(stname))
174 error(sprintf("sysgetsignals(sys,\"%s\",%d):only %d entries.\n", ... 174 error(sprintf("sysgetsignals(sys,\"%s\",%d):only %d entries.\n", ...
175 sigid,signum, rows(stname))); 175 sigid,signum, rows(stname)));
176 else 176 else
182 stname = stname(signum); 182 stname = stname(signum);
183 case(1), 183 case(1),
184 if(length(signum) > 1) 184 if(length(signum) > 1)
185 error("strflg=1, length(signum) = %d",length(signum)); 185 error("strflg=1, length(signum) = %d",length(signum));
186 endif 186 endif
187 stname = nth(stname,signum); 187 stname = stname{signum};
188 otherwise, 188 otherwise,
189 error ("invalid value of strflg = %e", strflg); 189 error ("invalid value of strflg = %e", strflg);
190 endswitch 190 endswitch
191 191
192 endif 192 endif