Cody

Solution 2117513

Submitted on 4 Feb 2020 by Asif Newaz
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
x=[1 5 9;2 6 10;3 nan 11;nan nan nan]; y_correct=[2 5.5 10]; y=average(x); assert(isequalwithequalnans(y,y_correct)) y=average(x,1); assert(isequalwithequalnans(y,y_correct)) y_correct=[5;6;7;nan]; y=average(x,2); assert(isequalwithequalnans(y,y_correct)) y_correct=x; y=average(x,3); assert(isequalwithequalnans(y,y_correct))

x = 1 5 9 2 6 10 3 NaN 11 NaN NaN NaN a = 2.0000 5.5000 10.0000 x = 1 5 9 2 6 10 3 NaN 11 NaN NaN NaN d = 1 a = 2.0000 5.5000 10.0000 x = 1 5 9 2 6 10 3 NaN 11 NaN NaN NaN d = 2 a = 5 6 7 NaN x = 1 5 9 2 6 10 3 NaN 11 NaN NaN NaN d = 3 a = 1 5 9 2 6 10 3 NaN 11 NaN NaN NaN

2   Pass
x=cat(3,[1 5 9;NaN 6 10;NaN 7 NaN;4 8 12],... [13 17 21;14 18 22;15 19 NaN;16 20 24]); y_correct=cat(3,[15 39 62]/6,[87 111 134]/6); y=average(x); assert(isequalwithequalnans(y,y_correct)) y=average(x,1); assert(isequalwithequalnans(y,y_correct)) y_correct=cat(3,[5;8;7;8],[17;18;17;20]); y=average(x,2); assert(isequalwithequalnans(y,y_correct)) y_correct=[7 11 15;14 12 16;15 13 NaN;10 14 18]; y=average(x,3); assert(isequalwithequalnans(y,y_correct))

x(:,:,1) = 1 5 9 NaN 6 10 NaN 7 NaN 4 8 12 x(:,:,2) = 13 17 21 14 18 22 15 19 NaN 16 20 24 a(:,:,1) = 2.5000 6.5000 10.3333 a(:,:,2) = 14.5000 18.5000 22.3333 x(:,:,1) = 1 5 9 NaN 6 10 NaN 7 NaN 4 8 12 x(:,:,2) = 13 17 21 14 18 22 15 19 NaN 16 20 24 d = 1 a(:,:,1) = 2.5000 6.5000 10.3333 a(:,:,2) = 14.5000 18.5000 22.3333 x(:,:,1) = 1 5 9 NaN 6 10 NaN 7 NaN 4 8 12 x(:,:,2) = 13 17 21 14 18 22 15 19 NaN 16 20 24 d = 2 a(:,:,1) = 5 8 7 8 a(:,:,2) = 17 18 17 20 x(:,:,1) = 1 5 9 NaN 6 10 NaN 7 NaN 4 8 12 x(:,:,2) = 13 17 21 14 18 22 15 19 NaN 16 20 24 d = 3 a = 7 11 15 14 12 16 15 13 NaN 10 14 18

3   Pass
x=zeros(2,1,0); y_correct=mean(x); y=average(x); assert(isequalwithequalnans(y,y_correct)) y=average(x,1); assert(isequalwithequalnans(y,y_correct)) y_correct=mean(x,2); y=average(x,2); assert(isequalwithequalnans(y,y_correct)) y_correct=mean(x,3); y=average(x,3); assert(isequalwithequalnans(y,y_correct))

x = 2×1×0 empty double array a = 1×1×0 empty double array x = 2×1×0 empty double array d = 1 a = 1×1×0 empty double array x = 2×1×0 empty double array d = 2 a = 2×1×0 empty double array x = 2×1×0 empty double array d = 3 a = NaN NaN

Suggested Problems

More from this Author10