Cody

Solution 1942738

Submitted on 19 Sep 2019 at 13:24
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)

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)

B = 2 B = 2 5 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)

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in blkavg (line 4) B(i,j) = mean(A((i-1)*subz(1)+(1:subz(1)),(j-1)*subz(2)+(1:subz(2)))) 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)

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in blkavg (line 4) B(i,j) = mean(A((i-1)*subz(1)+(1:subz(1)),(j-1)*subz(2)+(1:subz(2)))) 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)

Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. Error in blkavg (line 4) B(i,j) = mean(A((i-1)*subz(1)+(1:subz(1)),(j-1)*subz(2)+(1:subz(2)))) Error in Test5 (line 4) assert(norm(B-blkavg(A,subsz)) < 1e-10)