Cody

Problem 591. Create a patchwork matrix

Solution 2600155

Submitted on 23 Jun 2020 by Jens Kjærgaard Boldsen
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))

M = 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))

M = 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))

M = 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))

M = 0.1498 0.7588 0.0438 0.8179 0.1636 0.0409 0.2874 0.7474 0.3603 0.2139 0.4623 0.4064 0.7740 0.0400 0.9348 0.4301 0.6001 0.4182 0.7423 0.2765 0.2407 0.8254 0.8913 0.1911 0.4315 0.7517 0.8728 0.0269 0.6351 0.1023 0.9058 0.5889 0.5192 0.8277 0.1343 0.3529

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

M = 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{:})))

M = []

Suggested Problems

More from this Author11