Cody

Problem 44350. Breaking Out of the Matrix

Solution 1312410

Submitted on 24 Oct 2017 by Anselm Karl
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
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))

ans = 3 4 ans = 2 3 num_R = 2 num_C = 2 offset_R = 0 1 offset_C = 0 1

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

ans = 1 39 ans = 1 1 num_R = 1 num_C = 39 offset_R = 0 offset_C = Columns 1 through 29 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Columns 30 through 39 29 30 31 32 33 34 35 36 37 38

3   Pass
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]))

ans = 7 7 ans = 2 2 num_R = 6 num_C = 6 offset_R = 0 1 2 3 4 5 offset_C = 0 1 2 3 4 5

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

ans = 8 8 ans = 8 8 num_R = 1 num_C = 1 offset_R = 0 offset_C = 0

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

ans = 8 8 ans = 2 2 num_R = 7 num_C = 7 offset_R = 0 1 2 3 4 5 6 offset_C = 0 1 2 3 4 5 6

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

ans = 7 7 ans = 7 7 num_R = 1 num_C = 1 offset_R = 0 offset_C = 0

Suggested Problems

More from this Author80

Community Treasure Hunt

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

Start Hunting!