Cody

Problem 591. Create a patchwork matrix

Solution 3367073

Submitted on 24 Oct 2020 by A C
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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 1 0 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.0462 0.6109 0.5204 0.5739 0.9402 0.1403 m1 = 0.0462 0.6109 0.5204 0.5739 0.9402 0.1403 m2 = 0.3237 0.3161 0.4477 0.1032 0.0485 0.0193 m3 = 0.9926 0.2891 0.8037 0.7373 0.8279 0.5273 m4 = 0.4024 0.9948 0.8895 0.9766 0.2511 0.7117 m5 = 0.4931 0.5837 0.7917 0.7958 0.5392 0.1520 m6 = 0.1478 0.3453 0.7382 0.9016 0.1138 0.4194 A = 0.1478 0.3453 0.7382 0.4931 0.5837 0.7917 0.9016 0.1138 0.4194 0.7958 0.5392 0.1520 0.4024 0.9948 0.8895 0.9926 0.2891 0.8037 0.9766 0.2511 0.7117 0.7373 0.8279 0.5273 0.3237 0.3161 0.4477 0.0462 0.6109 0.5204 0.1032 0.0485 0.0193 0.5739 0.9402 0.1403

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

m1 = 0.8331 0.6826 0.5365 0.0210 0.0262 0.3602 A = 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{:})))

m1 = []


Community Treasure Hunt

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

Start Hunting!