Cody

Problem 43284. Form a square matrix from four square sub-matrices

Solution 1634954

Submitted on 28 Sep 2018
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   Fail
n=2; n1=1; n2=2; n3=3; n4=5; y = [1 0 2 2; 0 1 2 2; 3 3 5 0; 3 3 0 5]; assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

n1 = 1 0 0 1 n4 = 5 0 0 5 n2 = 2 2 2 2 n3 = 3 3 3 3 ycol1 = 1 0 3 3 0 1 3 3 ycol2 = 2 2 5 0 2 2 0 5

Undefined function or variable 'col1'. Error in CreateMatrix (line 9) y=[col1;col2] Error in Test1 (line 10) assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

2   Fail
n=2; n1=5; n2=2; n3=3; n4=-4; y = [5 0 2 2; 0 5 2 2; 3 3 -4 0; 3 3 0 -4]; assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

n1 = 5 0 0 5 n4 = -4 0 0 -4 n2 = 2 2 2 2 n3 = 3 3 3 3 ycol1 = 5 0 3 3 0 5 3 3 ycol2 = 2 2 -4 0 2 2 0 -4

Undefined function or variable 'col1'. Error in CreateMatrix (line 9) y=[col1;col2] Error in Test2 (line 10) assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

3   Fail
n=3; n1=3; n2=2; n3=7; n4=1; y = [3 0 0 2 2 2; 0 3 0 2 2 2; 0 0 3 2 2 2; 7 7 7 1 0 0; 7 7 7 0 1 0; 7 7 7 0 0 1]; assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

n1 = 3 0 0 0 3 0 0 0 3 n4 = 1 0 0 0 1 0 0 0 1 n2 = 2 2 2 2 2 2 2 2 2 n3 = 7 7 7 7 7 7 7 7 7 ycol1 = 3 0 0 7 7 7 0 3 0 7 7 7 0 0 3 7 7 7 ycol2 = 2 2 2 1 0 0 2 2 2 0 1 0 2 2 2 0 0 1

Undefined function or variable 'col1'. Error in CreateMatrix (line 9) y=[col1;col2] Error in Test3 (line 12) assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

4   Fail
n=2; n1=4; n2=8; n3=8; n4=2; y = [4 0 8 8; 0 4 8 8; 8 8 2 0; 8 8 0 2]; assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

n1 = 4 0 0 4 n4 = 2 0 0 2 n2 = 8 8 8 8 n3 = 8 8 8 8 ycol1 = 4 0 8 8 0 4 8 8 ycol2 = 8 8 2 0 8 8 0 2

Undefined function or variable 'col1'. Error in CreateMatrix (line 9) y=[col1;col2] Error in Test4 (line 10) assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

5   Fail
n=5; n1=4; n2=3; n3=2; n4=1; y = [4 0 0 0 0 3 3 3 3 3; 0 4 0 0 0 3 3 3 3 3; 0 0 4 0 0 3 3 3 3 3; 0 0 0 4 0 3 3 3 3 3; 0 0 0 0 4 3 3 3 3 3; 2 2 2 2 2 1 0 0 0 0; 2 2 2 2 2 0 1 0 0 0; 2 2 2 2 2 0 0 1 0 0; 2 2 2 2 2 0 0 0 1 0; 2 2 2 2 2 0 0 0 0 1]; assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

n1 = 4 0 0 0 0 0 4 0 0 0 0 0 4 0 0 0 0 0 4 0 0 0 0 0 4 n4 = 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 n2 = 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 n3 = 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ycol1 = 4 0 0 0 0 2 2 2 2 2 0 4 0 0 0 2 2 2 2 2 0 0 4 0 0 2 2 2 2 2 0 0 0 4 0 2 2 2 2 2 0 0 0 0 4 2 2 2 2 2 ycol2 = 3 3 3 3 3 1 0 0 0 0 3 3 3 3 3 0 1 0 0 0 3 3 3 3 3 0 0 1 0 0 3 3 3 3 3 0 0 0 1 0 3 3 3 3 3 0 0 0 0 1

Undefined function or variable 'col1'. Error in CreateMatrix (line 9) y=[col1;col2] Error in Test5 (line 16) assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

6   Fail
n=6; n1=4; n2=7; n3=1; n4=9; y = [4 0 0 0 0 0 7 7 7 7 7 7; 0 4 0 0 0 0 7 7 7 7 7 7; 0 0 4 0 0 0 7 7 7 7 7 7; 0 0 0 4 0 0 7 7 7 7 7 7; 0 0 0 0 4 0 7 7 7 7 7 7; 0 0 0 0 0 4 7 7 7 7 7 7; 1 1 1 1 1 1 9 0 0 0 0 0; 1 1 1 1 1 1 0 9 0 0 0 0; 1 1 1 1 1 1 0 0 9 0 0 0; 1 1 1 1 1 1 0 0 0 9 0 0; 1 1 1 1 1 1 0 0 0 0 9 0; 1 1 1 1 1 1 0 0 0 0 0 9]; assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

n1 = 4 0 0 0 0 0 0 4 0 0 0 0 0 0 4 0 0 0 0 0 0 4 0 0 0 0 0 0 4 0 0 0 0 0 0 4 n4 = 9 0 0 0 0 0 0 9 0 0 0 0 0 0 9 0 0 0 0 0 0 9 0 0 0 0 0 0 9 0 0 0 0 0 0 9 n2 = 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 n3 = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ycol1 = 4 0 0 0 0 0 1 1 1 1 1 1 0 4 0 0 0 0 1 1 1 1 1 1 0 0 4 0 0 0 1 1 1 1 1 1 0 0 0 4 0 0 1 1 1 1 1 1 0 0 0 0 4 0 1 1 1 1 1 1 0 0 0 0 0 4 1 1 1 1 1 1 ycol2 = 7 7 7 7 7 7 9 0 0 0 0 0 7 7 7 7 7 7 0 9 0 0 0 0 7 7 7 7 7 7 0 0 9 0 0 0 7 7 7 7 7 7 0 0 0 9 0 0 7 7 7 7 7 7 0 0 0 0 9 0 7 7 7 7 7 7 0 0 0 0 0 9

Undefined function or variable 'col1'. Error in CreateMatrix (line 9) y=[col1;col2] Error in Test6 (line 18) assert(isequal(CreateMatrix(n,n1,n2,n3,n4),y))

Suggested Problems

More from this Author37

Community Treasure Hunt

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

Start Hunting!