Cody

Problem 300. Remove NaN ?

Solution 1703006

Submitted on 5 Jan 2019 by Nikolaos Nikolaou
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 = magic(3);x(2,[1 3])= NaN; y_correct = [8 1 6;4 9 2]; assert(isequal(removeNaN(x),y_correct))

t = 3×3 logical array 0 0 0 1 0 1 0 0 0 t1 = 2 8 I = 2 2 J = 1 3 I = 2 I = 2 x = 8 1 6 4 9 2 i = 2 y = 8 1 6 4 9 2

2   Pass
x = [magic(4) ones(4,1)]; x(4,5) = NaN;x(3,2) = Inf;x(3,1)=NaN; y_correct = x(1:2,:); assert(isequal(removeNaN(x),y_correct))

t = 4×5 logical array 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 t1 = 3 20 I = 3 4 J = 1 5 I = 3 4 I = 4 3 x = 16 2 3 13 1 5 11 10 8 1 NaN Inf 6 12 1 i = 2 x = 16 2 3 13 1 5 11 10 8 1 i = 3 y = 16 2 3 13 1 5 11 10 8 1

3   Pass
x = ones(4);x(3,3)=NaN; y_correct = ones(3,4); assert(isequal(removeNaN(x),y_correct))

t = 4×4 logical array 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 t1 = 11 I = 3 J = 3 I = 3 I = 3 x = 1 1 1 1 1 1 1 1 1 1 1 1 i = 2 y = 1 1 1 1 1 1 1 1 1 1 1 1

4   Pass
x = [1; NaN]; y_correct = [1]; assert(isequal(removeNaN(x),y_correct))

t = 2×1 logical array 0 1 t1 = 2 I = 2 J = 1 I = 2 I = 2 x = 1 i = 2 y = 1

5   Pass
x = NaN; assert(isempty(removeNaN(x)))

t = logical 1 t1 = 1 I = 1 J = 1 I = 1 I = 1 x = 0×1 empty double column vector i = 2 y = 0×1 empty double column vector

6   Pass
x = [1:10 NaN]; assert(isempty(removeNaN(x)))

t = 1×11 logical array 0 0 0 0 0 0 0 0 0 0 1 t1 = 11 I = 1 J = 11 I = 1 I = 1 x = 0×11 empty double matrix i = 2 y = 0×11 empty double matrix

7   Pass
x = [1:10 NaN]'; y_correct = [1:10]'; assert(isequal(removeNaN(x),y_correct))

t = 11×1 logical array 0 0 0 0 0 0 0 0 0 0 1 t1 = 11 I = 11 J = 1 I = 11 I = 11 x = 1 2 3 4 5 6 7 8 9 10 i = 2 y = 1 2 3 4 5 6 7 8 9 10