comparison +blockmatrix/fromMatrix.m @ 208:40dda96c8c9c feature/grids

blockmatrix: Added function to convert regular matrix to blockmatrix.
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 15 Jun 2016 17:25:40 +0200
parents
children 3974dccff55b
comparison
equal deleted inserted replaced
207:d521e17f72b6 208:40dda96c8c9c
1 function bm = fromMatrix(A, div)
2 d1 = div{1};
3 d2 = div{2};
4 [n, m] = size(A);
5 if n ~= sum(d1) || m ~= sum(d2)
6 error('blockmatrix:fromMatrix:NonMatchingDim','The dimensions in div does not sum to the dimensions in A.');
7 end
8
9 bm = cell(length(d1), length(d2));
10 I = 1;
11 for i = 1:length(d1)
12 J = 1;
13 for j = 1:length(d2)
14 Asub = A(I:(I + d1(i)-1), J:(J + d2(j)-1));
15 if nnz(Asub) == 0
16 bm{i,j} = [];
17 else
18 bm{i,j} = Asub;
19 end
20 J = J + d2(j);
21 end
22 I = I + d1(i);
23 end
24 end