comparison scripts/control/system/sysdisc.m @ 4460:cef48c4b902d

[project @ 2003-07-11 18:37:48 by jwe]
author jwe
date Fri, 11 Jul 2003 18:37:48 +0000
parents 22bd65326ec1
children b8105302cfe8
comparison
equal deleted inserted replaced
4459:75ee1995d2b4 4460:cef48c4b902d
34 ## @end table 34 ## @end table
35 ## @end deftypefn 35 ## @end deftypefn
36 36
37 function [dsys, Adc, Cdc] = sysdisc (sys) 37 function [dsys, Adc, Cdc] = sysdisc (sys)
38 38
39 save_empty = empty_list_elements_ok; 39 save_warn_empty_list_elements = warn_empty_list_elements;
40 empty_list_elements_ok = 1; 40 unwind_protect
41 warn_empty_list_elements = 0;
41 42
42 if (nargin != 1) 43 if (nargin != 1)
43 usage("[dsys,Adc,Cdc] = sysdisc(sys)"); 44 usage("[dsys,Adc,Cdc] = sysdisc(sys)");
44 elseif (!isstruct(sys)) 45 elseif (!isstruct(sys))
45 error("sys must be in system data structure form"); 46 error("sys must be in system data structure form");
46 endif 47 endif
47 48
48 sys = sysupdate (sys, "ss"); 49 sys = sysupdate (sys, "ss");
49 [n_tot, st_c, st_d, y_c, y_d] = __syscont_disc__ (sys); # get ranges 50 [n_tot, st_c, st_d, y_c, y_d] = __syscont_disc__ (sys); # get ranges
50 51
51 ## assume there's nothing there; build partitions as appropriate 52 ## assume there's nothing there; build partitions as appropriate
52 Add = Adc = Bdd = Cdd = Cdc = Ddd = []; 53 Add = Adc = Bdd = Cdd = Cdc = Ddd = [];
53 54
54 if(isempty(st_d) & isempty(y_d)) 55 if(isempty(st_d) & isempty(y_d))
55 error("sysdisc: expecting discrete states and/or continous outputs"); 56 error("sysdisc: expecting discrete states and/or continous outputs");
56 elseif (isempty(st_d)) 57 elseif (isempty(st_d))
57 warning("sysdisc: no discrete states"); 58 warning("sysdisc: no discrete states");
58 elseif(isempty(y_d)) 59 elseif(isempty(y_d))
59 warning("sysdisc: no discrete outputs"); 60 warning("sysdisc: no discrete outputs");
60 endif 61 endif
61 62
62 [aa,bb,cc,dd] = sys2ss(sys); 63 [aa,bb,cc,dd] = sys2ss(sys);
63 if(!isempty(st_d) ) 64 if(!isempty(st_d) )
64 Add = aa( st_d , st_d); 65 Add = aa( st_d , st_d);
65 stname = sysgetsignals(sys,"st",st_d); 66 stname = sysgetsignals(sys,"st",st_d);
66 Bdd = bb( st_d , :); 67 Bdd = bb( st_d , :);
67 if(!isempty(st_c)) 68 if(!isempty(st_c))
68 Adc = aa( st_d , st_c); 69 Adc = aa( st_d , st_c);
70 endif
71 if(!isempty(y_d))
72 Cdd = cc(y_d , st_d);
73 endif
74 else
75 stname = [];
69 endif 76 endif
70 if(!isempty(y_d)) 77 if(!isempty(y_d))
71 Cdd = cc(y_d , st_d); 78 Ddd = dd(y_d , :);
79 outname = sysgetsignals(sys,"out",y_d);
80 if(!isempty(st_c))
81 Cdc = cc(y_d , st_c);
82 endif
83 else
84 outname=[];
72 endif 85 endif
73 else 86 inname = sysgetsignals(sys,"in");
74 stname = []; 87 outlist = 1:rows(outname);
75 endif 88
76 if(!isempty(y_d)) 89 if(!isempty(outname))
77 Ddd = dd(y_d , :); 90 tsam = sysgettsam(sys);
78 outname = sysgetsignals(sys,"out",y_d); 91 [nc,nz] = sysdimensions(sys);
79 if(!isempty(st_c)) 92 dsys = ss2sys(Add,Bdd,Cdd,Ddd,tsam,0,nz,stname,inname,outname,outlist);
80 Cdc = cc(y_d , st_c); 93 else
94 dsys=[];
81 endif 95 endif
82 else
83 outname=[];
84 endif
85 inname = sysgetsignals(sys,"in");
86 outlist = 1:rows(outname);
87 96
88 if(!isempty(outname)) 97 unwind_protect_cleanup
89 tsam = sysgettsam(sys); 98 warn_empty_list_elements = save_warn_empty_list_elements;
90 [nc,nz] = sysdimensions(sys); 99 end_unwind_protect
91 dsys = ss2sys(Add,Bdd,Cdd,Ddd,tsam,0,nz,stname,inname,outname,outlist);
92 else
93 dsys=[];
94 endif
95
96 empty_list_elements_ok = save_empty;
97 100
98 endfunction 101 endfunction