Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/blockMatIndex.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 % adds corresponding matrices of same sizes or empty inside cell array | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: blockMatAdd adds corresponding matrices of same sizes or empty inside | |
5 % cell array | |
6 % | |
7 % CALL: [cell3] = ssm.blockMatAdd(cell1,cell2) | |
8 % | |
9 % INPUTS: | |
10 % cell1 - cell array of matrices representing a matrix by blocs. | |
11 % blocs may be empty | |
12 % cell2 - cell array of matrices representing a matrix by blocs. | |
13 % blocs may be empty | |
14 % | |
15 % OUTPUTS: | |
16 % cell3 - cell array of matrices representing a matrix by blocs. | |
17 % blocs may be empty | |
18 % | |
19 % NOTE : function is private to the ssm class | |
20 % | |
21 % VERSION: '$Id: blockMatIndex.m,v 1.8 2011/02/02 19:25:30 adrien Exp $' | |
22 % | |
23 % TO DO : | |
24 % check ME in case of mixed symbolic and double | |
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
26 function a = blockMatIndex(amats, blockIndex1, portIndex1, blockIndex2, portIndex2 ) | |
27 %% filling binary array to check is location is empty | |
28 isEmpty = cellfun(@isempty, amats); | |
29 | |
30 Nrow = size(amats,1); | |
31 Ncol = size(amats,2); | |
32 | |
33 n1 = numel(blockIndex1); | |
34 n2 = numel(blockIndex2); | |
35 a = zeros(n1, n2); | |
36 | |
37 %% rebuilding input indexing vector | |
38 [groupedBlockIndex1, groupedPortIndex1, groupSize1, nGroups1, globalPortIndex1] = ssmblock.groupIndexes(blockIndex1, portIndex1); | |
39 [groupedBlockIndex2, groupedPortIndex2, groupSize2, nGroups2, globalPortIndex2] = ssmblock.groupIndexes(blockIndex2, portIndex2); | |
40 %% Copying content | |
41 for ii=1:nGroups1 | |
42 bi = groupedBlockIndex1(ii); | |
43 pi = groupedPortIndex1{ii}; | |
44 for jj=1:nGroups2 | |
45 bj = groupedBlockIndex2(jj); | |
46 if ~isEmpty(bi, bj) || min(bi,Nrow)==min(bj,Ncol) | |
47 % if we have a non-empty cell or we are on the extended diagonal | |
48 val = amats{bi, bj}(pi,groupedPortIndex2{jj}); | |
49 if isa(val, 'sym') && ~isa(a, 'sym') | |
50 a = sym(a); | |
51 end | |
52 a(globalPortIndex1{ii},globalPortIndex2{jj}) = val; | |
53 | |
54 end | |
55 end | |
56 end | |
57 | |
58 end | |
59 | |
60 | |
61 |