Cody

Problem 42854. Crunch that matrix!

Solution 2606446

Submitted on 24 Jun 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
a=reshape(1:36,6,[]); b=[sum(a(:,1:3),2) sum(a(:,4:6),2)]; m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-10)

m = 6 n = 6

Index in position 2 exceeds array bounds (must not exceed 6). Error in Test1 (line 3) m=matrix_crunch(a);

2   Fail
a=magic(9)-30; b=[sum(a(:,1:3),2) sum(a(:,4:6),2) sum(a(:,7:9),2)]; m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-10)

m = 9 n = 9

Index in position 2 exceeds array bounds (must not exceed 9). Error in Test2 (line 3) m=matrix_crunch(a);

3   Fail
a=rand(12); b=[sum(a(:,1:3),2) sum(a(:,4:6),2) sum(a(:,7:9),2) sum(a(:,10:12),2)]; m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-10)

m = 12 n = 12

Index in position 2 exceeds array bounds (must not exceed 12). Error in Test3 (line 3) m=matrix_crunch(a);

4   Fail
a=ones(18); b=3*ones(18,6); m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-10)

m = 18 n = 18

Index in position 2 exceeds array bounds (must not exceed 18). Error in Test4 (line 3) m=matrix_crunch(a);

5   Fail
a=magic(15)+j.*flipud(magic(15)); a=a(1:10,:)-rand(10,15); b=[sum(a(:,1:3),2) sum(a(:,4:6),2) sum(a(:,7:9),2) sum(a(:,10:12),2) sum(a(:,13:15),2)]; m=matrix_crunch(a); assert(max(max(abs(m-b)))<1e-10)

m = 10 n = 15

Index in position 2 exceeds array bounds (must not exceed 15). Error in Test5 (line 4) m=matrix_crunch(a);


Community Treasure Hunt

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

Start Hunting!