Cody

# Problem 591. Create a patchwork matrix

Solution 195992

Submitted on 24 Jan 2013 by J.R.! Menzinger
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
%% P = [1 0; 1 2]; m1 = eye(2); m2 = ones(2); M_correct = [1 0 0 0; 0 1 0 0; 1 0 1 1; 0 1 1 1]; assert(isequal(patchworkMatrix(P,m1,m2),M_correct))

``` ans = 1 0 0 1 1 0 0 1 ans = 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 1 ```

2   Pass
%% P = 2-eye(4); m1 = eye(2); m2 = ones(2); M_correct = [1 0 1 1 1 1 1 1; 0 1 1 1 1 1 1 1; 1 1 1 0 1 1 1 1; 1 1 0 1 1 1 1 1; 1 1 1 1 1 0 1 1; 1 1 1 1 0 1 1 1; 1 1 1 1 1 1 1 0; 1 1 1 1 1 1 0 1]; assert(isequal(patchworkMatrix(P,m1,m2),M_correct))

``` ans = 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 ans = 1 0 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ans = 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 ans = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 ```

3   Pass
%% P = [2 3 2 3]; m1 = 1; m2 = 2; m3 = 3; M_correct = [2 3 2 3]; assert(isequal(patchworkMatrix(P,m1,m2,m3),M_correct))

``` ans = 2 ans = 2 3 ans = 2 3 2 ans = 2 3 2 3 ```

4   Pass
%% P = [6 5; 4 3; 2 1]; m1 = rand(2,3); m2 = rand(2,3); m3 = rand(2,3); m4 = rand(2,3); m5 = rand(2,3); m6 = rand(2,3); M_correct = [m6 m5; m4 m3; m2 m1]; assert(isequal(patchworkMatrix(P,m1,m2,m3,m4,m5,m6),M_correct))

``` ans = 0.6225 0.6707 0.8289 0.2005 0.0567 0.9254 0.6148 0.6993 0.7462 0.9715 0.0996 0.2725 0.6372 0.8436 0.3452 0.7058 0.9491 0.4344 ans = 0.6225 0.6707 0.8289 0.4059 0.3051 0.3615 0.2005 0.0567 0.9254 0.3207 0.3552 0.8865 0.6148 0.6993 0.7462 0.7581 0.7930 0.3499 0.9715 0.0996 0.2725 0.8775 0.9402 0.3653 0.6372 0.8436 0.3452 0.3639 0.3336 0.5162 0.7058 0.9491 0.4344 0.9955 0.4128 0.3066 ```

5   Pass
%% P = zeros(2); m1 = rand(3,2); m2 = rand(3,2); m3 = rand(3,2); m4 = rand(3,2); m5 = rand(3,2); m6 = rand(3,2); M_correct = zeros(6,4); assert(isequal(patchworkMatrix(P,m1,m2,m3,m4,m5,m6),M_correct))

``` ans = 0 0 0 0 0 0 0 0 0 0 0 0 ans = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ```

6   Pass
%% P = []; m = cell(100); assert(isempty(patchworkMatrix(P,m{:})))

``` ```