Cody

# Problem 44350. Breaking Out of the Matrix

Solution 2879576

Submitted on 26 Aug 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   Fail
M=[1 4 7 10; 2 5 8 11; 3 6 9 12]; R=2;C=3; X(:,:,1) =[1 4 7 ; 2 5 8]; X(:,:,2) =[2 5 8 ; 3 6 9]; X(:,:,3) =[4 7 10 ; 5 8 11]; X(:,:,4) =[5 8 11 ; 6 9 12]; assert(isequal(BreakTheMatrix(M,R,C),X))

Assertion failed.

2   Fail
x=1:ceil(35+25*rand());r=1;c=1; M=BreakTheMatrix(x,r,c); assert(all(arrayfun(@(y) (M(:,:,y)==y),1:numel(x))))

Error using arrayfun Non-scalar in Uniform output, at index 1, output 1. Set 'UniformOutput' to false. Error in Test2 (line 3) assert(all(arrayfun(@(y) (M(:,:,y)==y),1:numel(x))))

3   Fail
x=eye(7);r=2;c=2; M=BreakTheMatrix(x,r,c); ids=[1 8 15 22 29 36]; urs=ids(1:5)+1; lls=urs+5; z=setxor(1:size(M,3),[ids urs lls]); a1=arrayfun(@(a) isequal(M(:,:,a),eye(2)),ids); a2=arrayfun(@(a) isequal(M(:,:,a),[0 1 ; 0 0]),urs); a3=arrayfun(@(a) isequal(M(:,:,a),[0 0 ; 1 0]),lls); a4=arrayfun(@(a) isequal(M(:,:,a),zeros(2)),z); assert(all([a1 a2 a3 a4]))

Index in position 3 exceeds array bounds. Error in Test3>@(a)isequal(M(:,:,a),eye(2)) (line 7) a1=arrayfun(@(a) isequal(M(:,:,a),eye(2)),ids); Error in Test3 (line 7) a1=arrayfun(@(a) isequal(M(:,:,a),eye(2)),ids);

4   Fail
u=ceil(10*rand())+4; x=magic(u);r=u;c=u; M=BreakTheMatrix(x,r,c); assert(isequal(M,x))

y(:,:,1) = 35 1 6 3 32 7 31 9 2 y(:,:,2) = 0 0 0 0 0 0 0 0 0 y(:,:,3) = 0 0 0 0 0 0 0 0 0 y(:,:,4) = 0 0 0 0 0 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0 0 y(:,:,14) = 0 0 0 0 0 0 0 0 0 y(:,:,15) = 0 0 0 0 0 0 0 0 0 y(:,:,16) = 0 0 0 0 0 0 0 0 0 y(:,:,1) = 35 1 6 3 32 7 31 9 2 y(:,:,2) = 3 32 7 31 9 2 8 28 33 y(:,:,3) = 31 9 2 8 28 33 30 5 34 y(:,:,4) = 8 28 33 30 5 34 4 36 29 y(:,:,5) = 1 6 26 32 7 21 9 2 22 y(:,:,6) = 32 7 21 9 2 22 28 33 17 y(:,:,7) = 0 0 0 0 0 0 0 0 0 y(:,:,8) = 0 0 0 0 0 0 0 0 0 y(:,:,9) = 0 0 0 0 0 0 0 0 0 y(:,:,10) = 0 0 0 0 0 0 0 0 0 y(:,:,11) = 0 0 0 0 0 0 0 0 0 y(:,:,12) = 0 0 0 0 0 0 0 0 0 y(:,:,13) = 0 0 0 0 0 0 0 0 0 y(:,:,14) = 0 0 0 0 0 0 0 0 0 y(:,:,15) = 0 0 0 0 0 0 0 0 0 y(:,:,16) = 0 0 0 0 0 0 0 0 0 y(:,:,1) = 35 1 6 3 32 7 31 9 2 y(:,:,2) = 3 32 7 31 9 2 8 28 33 y(:,:,3) = 31 9 2 8 28 33 30 5 34 y(:,:,4) = 8 28 33 30 5 34 4 36 29 y(:,:,5) = 1 6 26 32 7 21 9 2 22 y(:,:,6) = 32 7 21 9 2 22 28 33 17 y(:,:,7) = 9 2 22 28 33 17 5 34 12 y(:,:,8) = 0 0 0 0 0 0 0 0 0 y(:,:,9) = 0 0 0 0 0 0 0 0 0 y(:,:,10) = 0 0 0 0 0 0 0 0 0 y(:,:,11) = 0 0 0 0 0 0 0 0 0 y(:,:,12) = 0 0 0 0 0 0 0 0 0 y(:,:,13) = 0 0 0 0 0 0 0 0 0 y(:,:,14) = 0 0 0 0 0 0 0 0 0 y(:,:,15) = 0 0 0 0 0 0 0 0 0 y(:,:,16) = 0 0 0 0 0 0 0 0 0 y(:,:,1) = 35 1 6 3 32 7 31 9 2 y(:,:,2) = 3 32 7 31 9 2 8 28 33 y(:,:,3) = 31 9 2 8 28 33 30 5 34 y(:,:,4) = 8 28 33 30 5 34 4 36 29 y(:,:,5) = 1 6 26 32 7 21 9 2 22 y(:,:,6) = 32 7 21 9 2 22 28 33 17 y(:,:,7) = 9 2 22 28 33 17 5 34 12 y(:,:,8) = 28 33 17 5 34 12 36 29 13 y(:,:,9) = 0 0 0 0 0 0 0 0 0 y(:,:,10) = 0 0 0 0 0 0 0 0 0 y(:,:,11) = 0 0 0 0 0 0 0 0 0 y(:,:,12) = 0 0 0 0 0 0 0 0 0 y(:,:,13) = 0 0 0 0 0 0 0 0 0 y(:,:,14) = 0 0 0 0 0 0 0 0 0 y(:,:,15) = 0 0 0 0 0 0 0 0 0 y(:,:,16) = 0 0 0 0 0 0 0 0 0 y(:,:,1) = 35 1 6 3 32 7 31 9 2 y(:,:,2) = 3 32 7 31 9 2 8 28 33 y(:,:,3) = 31 9 2 8 28 33 30 5 34 y(:,:,4) = 8 28 33 30 5 34 4 36 29 y(:,:,5) = 1 6 26 32 7 21 9 2 22 y(:,:,6) = 32 7 21 9 2 22 28 33 17 y(:,:,7) = 9 2 22 28 33 17 5 34 12 y(:,:,8) = 28 33 17 5 34 12 36 29 13 y(:,:,9) = 6 26 19 7 21 23 2 22 27 y(:,:,10) = 0 0 0 0 0 0 0 0 0 y(:,:,11) = 0 0 0 0 0 0 0 0 0 y(:,:,12) = 0 0 0 0 0 0 0 0 0 y...

Assertion failed.

5   Fail
temp=ceil(8*rand)+3; x=ones(temp);r=2;c=2; M=BreakTheMatrix(x,r,c); assert(size(M,3)==(temp-1)^2); assert(all(arrayfun(@(a) isequal(M(:,:,a),ones(2)),1:size(M,3))))

Assertion failed.

6   Fail
x=eye(7);r=7;c=7; assert(isequal(x,BreakTheMatrix(x,r,c)))

y(:,:,1) = 1 0 0 0 1 0 0 0 1 y(:,:,2) = 0 0 0 0 0 0 0 0 0 y(:,:,3) = 0 0 0 0 0 0 0 0 0 y(:,:,4) = 0 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:,14) = 0 0 0 0 0 0 0 0 0 y(:,:,15) = 0 0 0 0 0 0 0 0 0 y(:,:,16) = 0 0 0 0 0 0 0 0 0 y(:,:,17) = 0 0 0 0 0 0 0 0 0 y(:,:,18) = 0 0 0 0 0 0 0 0 0 y(:,:,19) = 0 0 0 0 0 0 0 0 0 y(:,:,20) = 0 0 0 0 0 0 0 0 0 y(:,:,21) = 0 0 0 0 0 0 0 0 0 y(:,:,22) = 0 0 0 0 0 0 0 0 0 y(:,:,23) = 0 0 0 0 0 0 0 0 0 y(:,:,24) = 0 0 0 0 0 0 0 0 0 y(:,:,25) = 0 0 0 0 0 0 0 0 0 y(:,:,1) = 1 0 0 0 1 0 0 0 1 y(:,:,2) = 0 1 0 0 0 1 0 0 0 y(:,:,3) = 0 0 1 0 0 0 0 0 0 y(:,:,4) = 0 0 0 0 0 0 0 0 0 y(:,:,5) = 0 0 0 0 0 0 0 0 0 y(:,:,6) = 0 0 0 1 0 0 0 1 0 y(:,:,7) = 0 0 0 0 0 0 0 0 0 y(:,:,8) = 0 0 0 0 0 0 0 0 0 y(:,:,9) = 0 0 0 0 0 0 0 0 0 y(:,:,10) = 0 0 0 0 0 0 0 0 0 y(:,:,11) = 0 0 0 0 0 0 0 0 0 y(:,:,12) = 0 0 0 0 0 0 0 0 0 y(:,:,13) = 0 0 0 0 0 0 0 0 0 y(:,:,14) = 0 0 0 0 0 0 0 0 0 y(:,:,15) = 0 0 0 0 0 ...

Assertion failed.

### Community Treasure Hunt

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

Start Hunting!