Mercurial > hg > ltpda
comparison m-toolbox/classes/@ssm/blockMatAdd.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 % OPTIONNAL INPUTS: | |
16 % isnotempty_1 - logical array tells ~isequal(cell1{ii,jj},[]) | |
17 % isnotempty_2 - logical array tells ~isequal(cell2{ii,jj},[]) | |
18 % | |
19 % OUTPUTS: | |
20 % cell3 - cell array of matrices representing a matrix by blocs. | |
21 % blocs may be empty | |
22 % | |
23 % NOTE : function is private to the ssm class | |
24 % | |
25 % VERSION: '$Id: blockMatAdd.m,v 1.4 2010/08/27 13:02:45 adrien Exp $' | |
26 % | |
27 % TO DO : | |
28 % check ME in case of mixed symbolic and double | |
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
30 function a = blockMatAdd(varargin) | |
31 a=varargin{1}; | |
32 b =varargin{2}; | |
33 Nrow = size(a,1); | |
34 Ncol = size(a,2); | |
35 if nargin ==4 | |
36 error('please remove the emptiness array as arguments, as they are not used anymore') | |
37 else | |
38 for ii=1:Nrow | |
39 for jj=1:Ncol | |
40 if min(jj,Nrow)==min(ii,Ncol) | |
41 % if we are on the extended diagonal, matrices should be there, add! | |
42 try | |
43 a{ii,jj} = a{ii,jj} + b{ii,jj}; | |
44 catch ME | |
45 a{ii,jj} = sym(a{ii,jj}) + sym(b{ii,jj}); | |
46 end | |
47 elseif ~isequal(a{ii,jj}, []) && ~isequal(b{ii,jj}, []) | |
48 % if both matrices are non-empty | |
49 try | |
50 a{ii,jj} = a{ii,jj} + b{ii,jj}; | |
51 catch ME | |
52 a{ii,jj} = sym(a{ii,jj}) + sym(b{ii,jj}); | |
53 end | |
54 elseif ~isequal(b{ii,jj}, []) | |
55 % if only the b is not empty | |
56 a{ii,jj} = b{ii,jj}; | |
57 end | |
58 end | |
59 end | |
60 end | |
61 end |