comparison m-toolbox/classes/@ssm/reshuffle.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 % RESHUFFLE rearragnes a ssm object using the given inputs and outputs.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: rearranges a ssm object using the given inputs and outputs.
5 %
6 % CALL: sys = reshuffle(sys, inputs1, inputs2, inputs3, states,
7 % outputs, outputStates)
8 %
9 % INPUTS:
10 % 'sys' - ssm object
11 % 'inputs1' - these will constitute the input block 1 of the output
12 % ssm (order is user defined)
13 % 'inputs2' - these will constitute the input block 1 of the output
14 % ssm (order is user defined)
15 % 'inputs3' - these will constitute the input block 1 of the output
16 % ssm (order is user defined)
17 % 'states' - states to keep (order is user defined)
18 % 'outputs' - outputs to keep, first output block (order is user
19 % defined)
20 % 'outputStates' - states to return as an output, second output block
21 % (order is user defined)
22 %
23 % The inputs/states/outputs can only be indexed using a cellstr containing
24 % block names or port names.
25 %
26 % OUTPUTS:
27 %
28 % 'sys' - a ssm object.
29 %
30 % VERSION :
31 % $Id: reshuffle.m,v 1.7 2011/04/08 08:56:23 hewitson Exp $
32 %
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34
35 function sys = reshuffle(sys, inputs1, inputs2, inputs3, states, outputs, outputStates)
36
37 [iBlockInputs1 iPortInputs1] = findPortWithMixedNames( sys.inputs, inputs1 );
38 [iBlockInputs2 iPortInputs2] = findPortWithMixedNames( sys.inputs, inputs2 );
39 [iBlockInputs3 iPortInputs3] = findPortWithMixedNames( sys.inputs, inputs3 );
40 [iBlockStatesOut iPortStatesOut] = findPortWithMixedNames( sys.states, outputStates );
41 [iBlockStates iPortStates] = findPortWithMixedNames( sys.states, states );
42 [iBlockOutputsOut iPortOutputsOut] = findPortWithMixedNames( sys.outputs, outputs );
43
44 inputs1 = mergeBlocksWithPositionIndex(sys.inputs, iBlockInputs1, iPortInputs1, 'inputs1');
45 inputs2 = mergeBlocksWithPositionIndex(sys.inputs, iBlockInputs2, iPortInputs2, 'inputs2');
46 inputs3 = mergeBlocksWithPositionIndex(sys.inputs, iBlockInputs3, iPortInputs3, 'inputs3');
47 States = mergeBlocksWithPositionIndex(sys.states, iBlockStates, iPortStates, 'states');
48 StatesOut = mergeBlocksWithPositionIndex(sys.states, iBlockStatesOut, iPortStatesOut, 'statesOut');
49 OutputsOut = mergeBlocksWithPositionIndex(sys.outputs, iBlockOutputsOut, iPortOutputsOut, 'outputsOut');
50
51 % cell_mat lines wanted cols wanted
52 A = ssm.blockMatIndex(sys.amats, iBlockStates , iPortStates , iBlockStates , iPortStates );
53 C = ssm.blockMatIndex(sys.cmats, iBlockOutputsOut, iPortOutputsOut, iBlockStates , iPortStates );
54 B = ssm.blockMatIndex(sys.bmats, iBlockStates , iPortStates , iBlockInputs1, iPortInputs1);
55 D = ssm.blockMatIndex(sys.dmats, iBlockOutputsOut, iPortOutputsOut, iBlockInputs1, iPortInputs1);
56 E = ssm.blockMatIndex(sys.bmats, iBlockStates , iPortStates , iBlockInputs2, iPortInputs2);
57 F = ssm.blockMatIndex(sys.dmats, iBlockOutputsOut, iPortOutputsOut, iBlockInputs2, iPortInputs2);
58 G = ssm.blockMatIndex(sys.bmats, iBlockStates , iPortStates , iBlockInputs3, iPortInputs3);
59 H = ssm.blockMatIndex(sys.dmats, iBlockOutputsOut, iPortOutputsOut, iBlockInputs3, iPortInputs3);
60
61 Y = eye(sum(sys.statesizes));
62 Y = ssm.blockMatRecut(Y, sys.statesizes, sys.statesizes);
63 Cstates = ssm.blockMatIndex( Y, iBlockStatesOut, iPortStatesOut, iBlockStates , iPortStates );
64
65 sys.amats = {A};
66 sys.bmats = {B E G };
67 sys.cmats = {Cstates; C};
68 sys.dmats = {[] zeros(size(Cstates,1),size(F,2)) zeros(size(Cstates,1), size(H,2)) ;...
69 D F H };
70
71 sys.inputs = [inputs1 inputs2 inputs3];
72 sys.states = States ;
73 sys.outputs = [StatesOut OutputsOut];
74
75 end