Mercurial > repos > public > sbplib
comparison +blockmatrix/isBlockmatrix.m @ 203:764438b52541 feature/grids
blockmatrix: Added functions to test for block matrcies and divisions.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 15 Jun 2016 14:29:56 +0200 |
parents | |
children | a5f1b0267dba |
comparison
equal
deleted
inserted
replaced
202:e2fefb6f0746 | 203:764438b52541 |
---|---|
1 function b = isBlockmatrix(bm) | |
2 if ~iscell(bm) | |
3 b = false; | |
4 return | |
5 end | |
6 | |
7 % Make sure all blocks are numerica matrices | |
8 for i = 1:length(bm) | |
9 if ~isnumeric(bm{i}) | |
10 b = false; | |
11 return | |
12 end | |
13 end | |
14 | |
15 [N,M] = size(bm); | |
16 % Make sure column dimensions agree | |
17 for i = 1:N | |
18 d = []; | |
19 for j = 1:M | |
20 d_ij = size(bm{i,j},1); | |
21 if d_ij == 0 | |
22 continue | |
23 end | |
24 | |
25 if isempty(d) | |
26 d = d_ij; | |
27 continue | |
28 end | |
29 | |
30 if d ~= d_ij | |
31 b = false; | |
32 return | |
33 end | |
34 end | |
35 end | |
36 | |
37 % Make sure row dimensions agree | |
38 for j = 1:M | |
39 d = []; | |
40 for i = 1:N | |
41 d_ij = size(bm{i,j},2); | |
42 if d_ij == 0 | |
43 continue | |
44 end | |
45 | |
46 if isempty(d) | |
47 d = d_ij; | |
48 continue | |
49 end | |
50 | |
51 if d ~= d_ij | |
52 b = false; | |
53 return | |
54 end | |
55 end | |
56 end | |
57 | |
58 b = true; | |
59 end |