comparison m-toolbox/classes/@ssm/blockMatRecut.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 % cuts a matrix into blocks stored inside cell array
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: blockMatRecut cuts a matrix into blocks stored inside cell
5 % array. Blocks with zeros are nullified, except in the diagonal (to
6 % preserve information on matrix size)
7 %
8 % CALL: [cell3] = ssm.blockMatRecut(mat1,rowsizes,colsizes)
9 %
10 % INPUTS:
11 % mat1 - numeric array to be cut in pieces
12 % rowsizes - vector giving block height
13 % colsizes - vector giving block width
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: blockMatRecut.m,v 1.5 2011/04/08 08:56:23 hewitson Exp $'
22 %
23 % TO DO :
24 % check ME in case of mixed symbolic and double
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26
27 function a_out = blockMatRecut(a, rowsizes, colsizes)
28 % to deal with matrices whose size is not defined
29 rowrank = cumsum([1 rowsizes]);
30 colrank = cumsum([1 colsizes]);
31 Nrow = length(rowsizes);
32 Ncol = length(colsizes);
33 a_out = cell(Nrow, Ncol);
34
35 for i=1:Nrow
36 for j=1:Ncol
37 % getting position
38 rowmin = rowrank(i);
39 rowmax = rowrank(i+1)-1;
40 colmin = colrank(j);
41 colmax = colrank(j+1)-1;
42 % selecting data
43 content = a(rowmin:rowmax, colmin:colmax);
44
45 % filling block data
46 if min(i, Ncol)==min(j, Nrow)
47 % if we are on the extended diagonal
48
49 if isa(content, 'sym')
50 % try convert the sym to a double
51 try
52 a_out{i,j} = double(content);
53 catch
54 a_out{i,j} = content;
55 end
56 else
57 % cut a piece and keep the class appartenance (ex for logical)
58 a_out{i,j} = content;
59 end
60
61 else
62
63 % if we are not on the extended diagonal
64 if isempty(content)
65 % delete it if it is empty
66 a_out{i,j} = [];
67 elseif isa(a, 'sym')
68 try
69 % try convert the sym to a double
70 content = double(content);
71 if norm(content)==0
72 % delete it if it is a double filled with zeros
73 a_out{i,j} = [];
74 else
75 a_out{i,j} = content;
76 end
77 catch
78 a_out{i,j} = content;
79 end
80 elseif isa(content, 'logical')
81 % keep the logical as it is
82 a_out{i,j} = content;
83 elseif norm(content)==0
84 % delete it if it is a double filled with zeros
85 a_out{i,j}=[];
86 else
87 % copy it is a non-zero double
88 a_out{i,j} = content;
89 end
90
91 end
92
93 clear content
94 end
95 end
96 end