Cody

# Problem 42858. Block average ignoring NaN values

Solution 893288

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 = [1 2 3 4 5 6 7 8 NaN]; subsz = [1 3]; B = [2 5 (7+8)/2]; assert(norm(B-blknanavg(A,subsz)) < 1e-10)

cells = [1x3 double] [1x3 double] [1x3 double] cells = [1x3 double] [1x3 double] [1x3 double] cells = [1x3 double] [1x3 double] [1x3 double] B = 2 cells = [1x3 double] [1x3 double] [1x3 double] cells = [1x3 double] [1x3 double] [1x3 double] B = 2 5 cells = [1x3 double] [1x3 double] [1x2 double] cells = [1x3 double] [1x3 double] [1x2 double] B = 2.0000 5.0000 7.5000

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

cells = [3x1 double] [3x1 double] [3x1 double] cells = [3x1 double] [3x1 double] [3x1 double] cells = [1x3 double] [3x1 double] [3x1 double] B = 2 cells = [1x3 double] [2x1 double] [3x1 double] cells = [1x3 double] [1x2 double] [3x1 double] B = 2 5 cells = [1x3 double] [1x2 double] [2x1 double] cells = [1x3 double] [1x2 double] [1x2 double] B = 2 5 8

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

cells = [2x3 double] [2x3 double] [2x3 double] [2x3 double] cells = [1x5 double] [2x3 double] [2x3 double] [2x3 double] cells = [1x5 double] [2x3 double] [2x3 double] [2x3 double] B = 1 cells = [1x5 double] [1x3 double] [2x3 double] [2x3 double] cells = [1x5 double] [1x3 double] [2x3 double] [2x3 double] B = 1 2 cells = [1x5 double] [1x3 double] [2x3 double] [2x3 double] cells = [1x5 double] [1x3 double] [1x6 double] [2x3 double] B = 1 2 3 0 cells = [1x5 double] [1x3 double] [1x6 double] [1x3 double] cells = [1x5 double] [1x3 double] [1x6 double] [1x3 double] B = 1 2 3 4

4   Pass
A = rand(100,300); A(randperm(numel(A),10)) = NaN; subsz = size(A); B = mean(A(:),'omitnan'); assert(norm(B-blknanavg(A,subsz)) < 1e-10)

cells = [100x300 double] cells = [1x29990 double] cells = [1x29990 double] B = 0.4989

5   Pass
subsz = [4,6]; B = 10*rand(10,20); A = repelem(B,subsz(1),subsz(2)); A(randperm(numel(A),10)) = NaN; assert(norm(B-blknanavg(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] 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] cells = Columns 1 through 6 [1x24 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] ...