Mercurial > repos > public > sbplib
comparison +blockmatrix/toMatrix.m @ 206:50a323da7c7f feature/grids
blockmatrix: Added function to convert blockmatrix to a regular matrix.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 15 Jun 2016 16:31:24 +0200 |
parents | |
children | 46aa0b6a10cd |
comparison
equal
deleted
inserted
replaced
205:f0ef314e2070 | 206:50a323da7c7f |
---|---|
1 function A = toMatrix(bm) | |
2 if ~blockmatrix.isBlockmatrix(bm) | |
3 error('blockmatrix:toMatrix:NotABlockmatrix', 'Input is not a blockmatrix'); | |
4 end | |
5 | |
6 div = blockmatrix.getDivision(bm); | |
7 n = div{1}; | |
8 m = div{2}; | |
9 | |
10 N = sum(n); | |
11 M = sum(m); | |
12 | |
13 A = sparse(N,M); | |
14 | |
15 n_ind = [0 cumsum(n)]; | |
16 m_ind = [0 cumsum(m)]; | |
17 | |
18 for i = 1:size(bm,1) | |
19 for j = 1:size(bm,2) | |
20 if isempty(bm{i,j}) | |
21 continue | |
22 end | |
23 A(n_ind(i)+1:n_ind(i+1),m_ind(j)+1:m_ind(j+1)) = bm{i,j}; | |
24 end | |
25 end | |
26 end |