comparison m-toolbox/classes/@ssm/doSimplify.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 % DOSIMPLIFY enables to do model simplification. It is a private function
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 %
5 % DESCRIPTION: DOSIMPLIFY allows to eliminate input/state/output variables.
6 %
7 % CALL: [ssm] = DOSIMPLIFY(ssm, options); (private)
8 %
9 % INPUTS :
10 % ssm - a ssm object
11 % options - an options plist
12 %
13 % OPTIONS :
14 % plist with parameters 'inputs', 'states' and 'outputs' to indicate which
15 % inputs, states and outputs variables are taken in account. This requires
16 % proper variable naming. If a variable called appears more that once it
17 % will be used once only.
18 % The field may be :
19 % - a cellstr containing the resp. input/state/output *variable* names
20 % - a logical indexing the resp. input/state/output
21 % *variables*. Index is stored in a cell array, each cell
22 % correponding to one input/state/output block.
23 % - a double indexing the resp. input/state/output
24 % *variables*. Index is stored in a cell array, each cell
25 % correponding to one input/state/output block.
26 % - 'ALL', this string indicates all i/o variables will be
27 % given
28 %
29 % OUTPUTS:
30 % The output array are of size Nsys*Noptions
31 % sys_out - (array of) ssm objects without the specified information
32 %
33 %
34 function varargout = doSimplify(varargin)
35
36 % Collect all SSMs and plists
37 [sys, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm');
38 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist');
39 if ~isempty(rest)
40 pl = combine(pl, plist(rest{:}));
41 end
42 pl = combine(pl, getDefaultPlist());
43
44 if numel(sys) ~= 1
45 error('### Please input (only) one SSM model');
46 end
47
48 % Decide on a deep copy or a modify, depending on the output
49 sys = copy(sys, nargout);
50
51 %% retrieving indexes
52 indexInputs = makePortLogicalIndex( sys.inputs, find(pl,'inputs') );
53 indexStates = makePortLogicalIndex( sys.states, find(pl,'states') );
54 indexOutputs = makePortLogicalIndex( sys.outputs, find(pl,'outputs') );
55
56 %% pruning the object fields and assigning fields
57 % cell_mat lines wanted cols wanted
58 sys.amats = ssm.blockMatPrune(sys.amats, indexStates, indexStates);
59 sys.bmats = ssm.blockMatPrune(sys.bmats, indexStates, indexInputs);
60 sys.cmats = ssm.blockMatPrune(sys.cmats, indexOutputs, indexStates);
61 sys.dmats = ssm.blockMatPrune(sys.dmats, indexOutputs, indexInputs);
62
63 sys.inputs = applyPortLogicalIndex(sys.inputs, indexInputs );
64 sys.states = applyPortLogicalIndex(sys.states, indexStates );
65 sys.outputs = applyPortLogicalIndex(sys.outputs, indexOutputs );
66
67 %% output
68 varargout{1} = sys;
69
70 end
71
72
73 %--------------------------------------------------------------------------
74 % Get Default Plist
75 %--------------------------------------------------------------------------
76 function pl = getDefaultPlist()
77 pl = plist();
78
79 p = param({'inputs', 'input index'}, 'ALL');
80 pl.append(p);
81
82 p = param({'states', 'states index'}, 'ALL');
83 pl.append(p);
84
85 p = param({'outputs', 'output index'}, 'ALL');
86 pl.append(p);
87
88 end