Cody

Problem 42856. Block average

Solution 893291

Submitted on 22 May 2016 by Steve
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)

cells = [1x2 double] [1x2 double] [1x2 double] B = 1 B = 1 2 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)

cells = [3x1 double] [3x1 double] [3x1 double] B = 2 B = 2 5 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)

cells = [2x3 double] [2x3 double] [2x3 double] [2x3 double] B = 1 B = 1 2 B = 1 2 3 0 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)

cells = [100x300 double] B = 0.4979

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)

cells = Columns 1 through 6 [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] Columns 7 through 12 [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] Columns 13 through 18 [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] Columns 19 through 20 [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] [4x6 double] B = 2.3119 B = 2.3119 0.8815 B = 2.3119 0.8815 4.1000 B = 2.3119 0.8815 4.1000 7.8663 B = 2.3119 0.8815 4.1000 7.8663 3.8128 B = 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 B = 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 B = 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 B = 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Column 10 7.9457 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 11 7.9457 3.8301 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 12 7.9457 3.8301 6.4833 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 13 7.9457 3.8301 6.4833 9.3540 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 14 7.9457 3.8301 6.4833 9.3540 3.0767 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 15 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 16 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 17 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 Column 19 9.9102 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 Columns 19 through 20 9.9102 0.6533 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 7.3491 0 0 0 0 0 0 0 0 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.9102 0.6533 0 0 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 7.3491 0.9255 0 0 0 0 0 0 0 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.9102 0.6533 0 0 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 7.3491 0.9255 9.6469 0 0 0 0 0 0 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.9102 0.6533 0 0 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 7.3491 0.9255 9.6469 7.5531 0 0 0 0 0 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.9102 0.6533 0 0 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 7.3491 0.9255 9.6469 7.5531 5.1497 0 0 0 0 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.9102 0.6533 0 0 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 7.3491 0.9255 9.6469 7.5531 5.1497 1.1086 0 0 0 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.9102 0.6533 0 0 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 7.3491 0.9255 9.6469 7.5531 5.1497 1.1086 1.7782 0 0 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.9102 0.6533 0 0 B = Columns 1 through 9 2.3119 0.8815 4.1000 7.8663 3.8128 8.2894 2.0817 3.4267 3.3025 7.3491 0.9255 9.6469 7.5531 5.1497 1.1086 1.7782 7.1600 0 Columns 10 through 18 7.9457 3.8301 6.4833 9.3540 3.0767 7.6554 4.6072 0.1871 1.0958 0 0 0 0 0 0 ...