Cody

# Problem 42856. Block average

Solution 1436088

Submitted on 7 Feb 2018 by Andrew Dobrovolc
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   Pass
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 B = 1 0 0 0 t = 1 B = 1 2 0 0 t = 1 B = 1 2 3 0 t = 1 B = 1 2 3 4

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

r = 1 c = 1 t = 1 B = 0.5011

5   Pass
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 B = Columns 1 through 18 3.9499 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 t = 1 B = Columns 1 through 18 3.9499 6.4886 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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