comparison m-toolbox/classes/@ssm/double.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % Convert a statespace model object to double arrays for given i/o
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: double converts a statespace model object to double arrays.
5 %
6 % CALL: [A B C D Ts ...
7 % inputvarnames ssvarnames outputvarnames ...
8 % inputvarunits ssvarunits outputvarunits ] = double(ssm, pl);
9 %
10 % INPUTS :
11 % ssm - a ssm object
12 % pl - an options plist
13 %
14 % OPTIONS :
15 % plist with parameters 'inputs', 'states' and 'outputs' to indicate which
16 % inputs, states and outputs variables are taken in account. This requires
17 % proper variable naming. If a variable called appears more that once it
18 % will be used once only.
19 % The field may be :
20 % - a cellstr containing the resp. input/state/output *variable* names
21 % - a logical indexing the resp. input/state/output *variables*
22 % names. Index is stored in a cell array, each cell
23 % correponding to one input/state/output block.
24 % - a double indexing the resp. input/state/output *variables*
25 % names. Index is stored in a cell array, each cell
26 % correponding to one input/state/output block.
27 % - 'ALL', this string indicates all i/o variables will be
28 % given
29 %
30 %
31 % OUTPUTS : A - the As matrices in one double array
32 % B - the Bs matrices in one double array
33 % C - the Cs matrices in one double array
34 % D - the Ds matrices in one double array
35 % Ts - the sampling time of the system. 0 is
36 % continuous
37 % inputvarnames - the variable names corresponding to the
38 % columns of B and D
39 % ssvarnames - the variable names corresponding to the
40 % rows of A and B, cols. of A and C
41 % outputvarnames - the variable names corresponding to the
42 % rows of C and D
43 % inputvarunits - the variable names corresponding to the
44 % columns of B and D
45 % ssvarunits - the variable names corresponding to the
46 % rows of A and B, cols. of A and C
47 % outputunits - the variable names corresponding to the
48 % rows of C and D
49 %
50 %
51 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'double')">Parameters Description</a>
52 %
53 % VERSION: $Id: double.m,v 1.44 2011/04/08 08:56:22 hewitson Exp $
54 %
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
57 function varargout = double(varargin)
58
59 %% starting initial checks
60 % Check if this is a call for parameters
61 if utils.helper.isinfocall(varargin{:})
62 varargout{1} = getInfo(varargin{3});
63 return
64 end
65
66 utils.helper.msg(utils.const.msg.OMNAME, ['running ', mfilename]);
67
68 in_names = cell(size(varargin));
69 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
70 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist');
71 if ~isempty(rest)
72 pl = combine(pl, plist(rest{:}));
73 end
74 pl = combine(pl, getDefaultPlist());
75
76 if numel(sys)~=1
77 error('double takes exactly one ssm as input')
78 elseif ~sys.isnumerical % checking system is numeric
79 error(['error in double : system named ' sys.name ' is not numeric'])
80 end
81
82 %% begin function body
83
84 %making model simplifications, and deepcopy
85 indexInputs = makePortLogicalIndex( sys.inputs, find(pl,'inputs') );
86 indexStates = makePortLogicalIndex( sys.states, find(pl,'states') );
87 indexOutputs = makePortLogicalIndex( sys.outputs, find(pl,'outputs') );
88
89 %% pruning the object fields and assigning fields
90 % cell_mat lines wanted cols wanted
91 sys.amats = ssm.blockMatPrune(sys.amats, indexStates, indexStates);
92 sys.bmats = ssm.blockMatPrune(sys.bmats, indexStates, indexInputs);
93 sys.cmats = ssm.blockMatPrune(sys.cmats, indexOutputs, indexStates);
94 sys.dmats = ssm.blockMatPrune(sys.dmats, indexOutputs, indexInputs);
95
96 sys.inputs = applyPortLogicalIndex(sys.inputs, indexInputs );
97 sys.states = applyPortLogicalIndex(sys.states, indexStates );
98 sys.outputs = applyPortLogicalIndex(sys.outputs, indexOutputs );
99
100 % sys = doSimplify(sys0, pl);
101
102 % Convert to double arrays
103 A = ssm.blockMatFusion(sys.amats, sys.sssizes, sys.sssizes);
104 B = ssm.blockMatFusion(sys.bmats, sys.sssizes, sys.inputsizes);
105 C = ssm.blockMatFusion(sys.cmats, sys.outputsizes, sys.sssizes);
106 D = ssm.blockMatFusion(sys.dmats, sys.outputsizes, sys.inputsizes);
107 Ts = sys.timestep;
108
109 inputvarnames = cell(1,sum(sys.inputsizes));
110 inputunit = unit.initObjectWithSize(1,sum(sys.inputsizes));
111 k=1;
112 for i=1:sys.Ninputs
113 for j=1:sys.inputsizes(i)
114 inputvarnames{k} = sys.inputs(i).ports(j).name;
115 inputunit(k) = sys.inputs(i).ports(j).units;
116 k = k+1;
117 end
118 end
119 ssvarnames = cell(1,sum(sys.sssizes));
120 ssunit = unit.initObjectWithSize(1,sum(sys.inputsizes));
121 k=1;
122 for i=1:sys.Nss
123 for j=1:sys.sssizes(i)
124 ssvarnames{k} = sys.states(i).ports(j).name;
125 ssunit(k) = sys.states(i).ports(j).units;
126 k = k+1;
127 end
128 end
129 outputvarnames = cell(1,sum(sys.outputsizes));
130 outputunit = unit.initObjectWithSize(1,sum(sys.inputsizes));
131 k=1;
132 for i=1:sys.Noutputs
133 for j=1:sys.outputsizes(i)
134 outputvarnames{k} = sys.outputs(i).ports(j).name;
135 outputunit(k) = sys.outputs(i).ports(j).units;
136 k = k+1;
137 end
138 end
139
140
141 %% parsing output
142 varargout = {...
143 A B C D Ts ...
144 inputvarnames ssvarnames outputvarnames ...
145 inputunit ssunit outputunit ...
146 };
147
148 end
149
150 %--------------------------------------------------------------------------
151 % Get Info Object
152 %--------------------------------------------------------------------------
153 function ii = getInfo(varargin)
154
155 if nargin == 1 && strcmpi(varargin{1}, 'None')
156 sets = {};
157 pl = [];
158 else
159 sets = {'Default'};
160 pl = getDefaultPlist;
161 end
162 % Build info object
163 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.output, '$Id: double.m,v 1.44 2011/04/08 08:56:22 hewitson Exp $', sets, pl);
164 end
165
166
167 %--------------------------------------------------------------------------
168 % Get Default Plist
169 %--------------------------------------------------------------------------
170 function pl = getDefaultPlist()
171
172 pl = plist();
173
174 p = param({'inputs', 'A cell-array of input ports.'}, 'ALL');
175 pl.append(p);
176
177 p = param({'states', 'A cell-array of state ports.'}, 'ALL');
178 pl.append(p);
179
180 p = param({'outputs', 'A cell-array of output ports.'}, 'ALL');
181 pl.append(p);
182
183
184 end