Cody

Problem 42858. Block average ignoring NaN values

Solution 1695354

Submitted on 18 Dec 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   Fail
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)

Undefined function 'nanmean' for input arguments of type 'double'. Error in blknanavg (line 12) B(i,j) = nanmean(t(:)); Error in Test1 (line 4) assert(norm(B-blknanavg(A,subsz)) < 1e-10)

2   Fail
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)

Undefined function 'nanmean' for input arguments of type 'double'. Error in blknanavg (line 12) B(i,j) = nanmean(t(:)); Error in Test2 (line 4) assert(norm(B-blknanavg(A,subsz)) < 1e-10)

3   Fail
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)

Undefined function 'nanmean' for input arguments of type 'double'. Error in blknanavg (line 12) B(i,j) = nanmean(t(:)); Error in Test3 (line 8) assert(norm(B-blknanavg(A,subsz)) < 1e-10)

4   Fail
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)

Undefined function 'nanmean' for input arguments of type 'double'. Error in blknanavg (line 12) B(i,j) = nanmean(t(:)); Error in Test4 (line 5) assert(norm(B-blknanavg(A,subsz)) < 1e-10)

5   Fail
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)

Undefined function 'nanmean' for input arguments of type 'double'. Error in blknanavg (line 12) B(i,j) = nanmean(t(:)); Error in Test5 (line 5) assert(norm(B-blknanavg(A,subsz)) < 1e-10)