Cody

Problem 591. Create a patchwork matrix

Solution 3367013

Submitted on 24 Oct 2020
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))

m1 = 1 0 0 1 m1 = 1 0 0 1 m2 = 1 1 1 1 A = 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 A = 1 0 0 0 0 1 0 0 1 0 0 0 0 1 0 0 A = 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))

m1 = 1 0 0 1 m1 = 1 0 0 1 m2 = 1 1 1 1 A = 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 A = 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0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 0 0 1 1 1 1 1 0 0 1 1 1 0 1 1 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 A = 1 0 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 1 1 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 0 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 A = 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 0 0 1 1 1 1 0 1 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 A = 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 0 0 1 1 1 1 1 1 0 0 A = 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))

m1 = 1 A = 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))

m1 = 0.2940 0.8455 0.5808 0.8265 0.2229 0.1370 m1 = 0.2940 0.8455 0.5808 0.8265 0.2229 0.1370 m2 = 0.8353 0.8038 0.3729 0.3768 0.2864 0.3816 m3 = 0.6331 0.3154 0.1609 0.1604 0.7933 0.2930 m4 = 0.9916 0.2719 0.6931 0.7777 0.5833 0.6084 m5 = 0.4941 0.9935 0.8995 0.0325 0.3489 0.1697 m6 = 0.1558 0.7907 0.5669 0.6281 0.6666 0.8195 A = 0.1558 0.7907 0.5669 0.4941 0.9935 0.8995 0.6281 0.6666 0.8195 0.0325 0.3489 0.1697 0.9916 0.2719 0.6931 0.6331 0.3154 0.1609 0.7777 0.5833 0.6084 0.1604 0.7933 0.2930 0.8353 0.8038 0.3729 0.2940 0.8455 0.5808 0.3768 0.2864 0.3816 0.8265 0.2229 0.1370

5   Fail
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))

m1 = 0.2757 0.4053 0.2967 0.8339 0.8856 0.3151 m1 = 0.2757 0.4053 0.2967 0.8339 0.8856 0.3151 m2 = 0.3855 0.8717 0.3381 0.9750 0.0270 0.2181

Assertion failed.

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

m1 = []

Suggested Problems

More from this Author11

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!