Cody

Problem 42856. Block average

Solution 1436086

Submitted on 7 Feb 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   Pass
A = [2 0 1 3 5 7]; subsz = [1 2]; B = [1 2 6]; assert(norm(B-blkavg(A,subsz)) < 1e-10)

r = 1 c = 1 c = 1 3 c = 1 3 5 t = 1 B = 1 0 0 t = 1 B = 1 2 0 t = 1 B = 1 2 6

2   Pass
A = [1 2 3 4 5 6 7 8 9].'; subsz = [3,1]; B = [2 5 8].'; assert(norm(B-blkavg(A,subsz)) < 1e-10)

r = 1 r = 1 4 r = 1 4 7 c = 1 t = 1 B = 2 0 0 t = 1 B = 2 5 0 t = 1 B = 2 5 8

3   Fail
A = [1 1 1 2 2 2 1 1 1 2 2 2 3 3 3 4 4 4 3 3 3 4 4 4]; subsz = [2 3]; B = [1 2 3 4]; assert(norm(B-blkavg(A,subsz)) < 1e-10)

r = 1 r = 1 3 c = 1 c = 1 4 t = 1

Assignment has more non-singleton rhs dimensions than non-singleton subscripts Error in blkavg (line 14) B(i,m) = mean(A(r(i):re,c(m):ce)) Error in Test3 (line 8) assert(norm(B-blkavg(A,subsz)) < 1e-10)

4   Fail
A = rand(100,300); subsz = size(A); B = mean(A(:)); assert(norm(B-blkavg(A,subsz)) < 1e-10)

r = 1 c = 1 t = 1

Assignment has more non-singleton rhs dimensions than non-singleton subscripts Error in blkavg (line 14) B(i,m) = mean(A(r(i):re,c(m):ce)) Error in Test4 (line 4) assert(norm(B-blkavg(A,subsz)) < 1e-10)

5   Fail
subsz = [4,6]; B = 10*rand(10,20); A = repelem(B,subsz(1),subsz(2)); assert(norm(B-blkavg(A,subsz)) < 1e-10)

r = 1 r = 1 5 r = 1 5 9 r = 1 5 9 13 r = 1 5 9 13 17 r = 1 5 9 13 17 21 r = 1 5 9 13 17 21 25 r = 1 5 9 13 17 21 25 29 r = 1 5 9 13 17 21 25 29 33 r = 1 5 9 13 17 21 25 29 33 37 c = 1 c = 1 7 c = 1 7 13 c = 1 7 13 19 c = 1 7 13 19 25 c = 1 7 13 19 25 31 c = 1 7 13 19 25 31 37 c = 1 7 13 19 25 31 37 43 c = 1 7 13 19 25 31 37 43 49 c = 1 7 13 19 25 31 37 43 49 55 c = 1 7 13 19 25 31 37 43 49 55 61 c = 1 7 13 19 25 31 37 43 49 55 61 67 c = 1 7 13 19 25 31 37 43 49 55 61 67 73 c = 1 7 13 19 25 31 37 43 49 55 61 67 73 79 c = 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 c = 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 c = 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 c = 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 c = 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 c = 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 115 t = 1

Assignment has more non-singleton rhs dimensions than non-singleton subscripts Error in blkavg (line 14) B(i,m) = mean(A(r(i):re,c(m):ce)) Error in Test5 (line 4) assert(norm(B-blkavg(A,subsz)) < 1e-10)