Cody

Problem 42858. Block average ignoring NaN values

Solution 1942852

Submitted on 19 Sep 2019 by Augusto Mazzei
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)

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

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

B = 1 B = 1 2 B = 1 2 3 0 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)

B = 0.4974

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)

B = 7.1069 B = 7.1069 5.4897 B = 7.1069 5.4897 3.9630 B = 7.1069 5.4897 3.9630 2.3533 B = 7.1069 5.4897 3.9630 2.3533 7.8406 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 B = 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 Column 19 9.8601 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 Columns 19 through 20 9.8601 4.3692 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 0 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 0 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 0 0 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 9.2662 0 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 9.2662 5.2824 0 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 9.2662 5.2824 0.3689 0 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 9.2662 5.2824 0.3689 8.0852 0 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 9.2662 5.2824 0.3689 8.0852 8.4164 0 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 9.2662 5.2824 0.3689 8.0852 8.4164 4.6635 0 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 9.2662 5.2824 0.3689 8.0852 8.4164 4.6635 4.2203 0 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 9.2662 5.2824 0.3689 8.0852 8.4164 4.6635 4.2203 5.2533 0 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 8.1406 9.2662 5.2824 0.3689 8.0852 8.4164 4.6635 4.2203 5.2533 1.0047 0 0 Columns 19 through 20 9.8601 4.3692 0 0 B = Columns 1 through 18 7.1069 5.4897 3.9630 2.3533 7.8406 8.4321 1.6639 6.4866 8.3069 2.4983 3.7023 3.9357 8.9704 6.1475 2.1282 8.9040 7.1778 2.3270 3.5454 6.4952 2.4774 9.6493 3.2725 7.2315 ...