comparison +blockmatrix/fromMatrix.m @ 886:8894e9c49e40 feature/timesteppers

Merge with default for latest changes
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 15 Nov 2018 16:36:21 -0800
parents 3974dccff55b
children
comparison
equal deleted inserted replaced
816:b5e5b195da1e 886:8894e9c49e40
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} = sparse(d1(i), d2(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