Mercurial > repos > public > sbplib
comparison +blockmatrix/fromMatrixTest.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 | a5f1b0267dba |
comparison
equal
deleted
inserted
replaced
207:d521e17f72b6 | 208:40dda96c8c9c |
---|---|
1 function tests = fromMatrixTest() | |
2 tests = functiontests(localfunctions); | |
3 end | |
4 | |
5 function testErrorNonMatchingDim(testCase) | |
6 in = { | |
7 {magic(5), {[1 2 3], [4]}}, | |
8 {magic(5), {[1 1 1 1 1 1], [5]}}, | |
9 {magic(5), {[5], [1 1 1 1 1 1]}}, | |
10 {ones(4,2),{[2 3],[2]}}, | |
11 {ones(4,2),{[2 2],[3]}}, | |
12 }; | |
13 | |
14 for i = 1:length(in) | |
15 testCase.verifyError(@()blockmatrix.fromMatrix(in{i}{:}),'blockmatrix:fromMatrix:NonMatchingDim'); | |
16 end | |
17 end | |
18 | |
19 function testFromMatrix(testCase) | |
20 cases = { | |
21 { | |
22 {[],{[],[]}}, | |
23 {} | |
24 }, | |
25 { | |
26 { | |
27 magic(3), | |
28 {[3],[3]} | |
29 }, | |
30 {magic(3)} | |
31 }, | |
32 { | |
33 { | |
34 magic(3), | |
35 {[1 1 1],[1 1 1]} | |
36 }, | |
37 mat2cell(magic(3),[1 1 1],[1 1 1]) | |
38 }, | |
39 { | |
40 { | |
41 [17 24 1 8 15; 23 5 7 14 16; 4 6 13 20 22; 10 12 19 21 3; 11 18 25 2 9], | |
42 {[1 4],[2 3]} | |
43 }, | |
44 { | |
45 [17 24], [1 8 15]; | |
46 [23 5; 4 6; 10 12; 11 18], [7 14 16; 13 20 22; 19 21 3; 25 2 9]; | |
47 }; | |
48 }, | |
49 }; | |
50 for i = 1:length(cases) | |
51 out = convertToFull(blockmatrix.fromMatrix(cases{i}{1}{:})); | |
52 expected = cases{i}{2}; | |
53 testCase.verifyEqual(out,expected); | |
54 end | |
55 end | |
56 | |
57 function C = convertToFull(C) | |
58 [N,M] = size(C); | |
59 for i = 1:N | |
60 for j = 1:M | |
61 C{i,j} = full(C{i,j}); | |
62 end | |
63 end | |
64 end |