Cody

Problem 694. Remove NaNs and numbers adjacent to NaNs

Solution 1722360

Submitted on 7 Feb 2019
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
x=[1 2 3 NaN 4 5 6]; y_correct=[1 2 5 6]; assert(isequal(NaN_window_delete(x),y_correct))

y = 1×7 logical array 0 0 0 1 0 0 0 ans = logical 0 y = 1×5 logical array 0 0 0 1 0 y = 1×2 logical array 0 0

Assertion failed.

2   Fail
x=[10 20 3 NaN 4 50 NaN 6]; y_correct=[10 20]; assert(isequal(NaN_window_delete(x),y_correct))

y = 1×8 logical array 0 0 0 1 0 0 1 0 ans = logical 0 y = 1×6 logical array 0 0 0 1 0 0 y = 1×3 logical array 0 0 0

Index exceeds the number of array elements (3). Error in NaN_window_delete (line 13) if y(i) == 1 Error in Test2 (line 3) assert(isequal(NaN_window_delete(x),y_correct))

3   Fail
x=[NaN 20 3 5 4 50 55 NaN]; y_correct=[3 5 4 50]; assert(isequal(NaN_window_delete(x),y_correct))

y = 1×8 logical array 1 0 0 0 0 0 0 1 y = 1×6 logical array 0 0 0 0 0 1

Assertion failed.

4   Fail
x=[10 20 3 5 NaN 4 50 55 NaN 60 80 90 NaN 100 110 ]; y_correct=[10 20 3 50 80 110]; assert(isequal(NaN_window_delete(x),y_correct))

y = 1×15 logical array 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 ans = logical 0 y = 1×13 logical array 0 0 0 0 1 0 0 0 1 0 0 0 1 y = 1×10 logical array 0 0 0 0 0 1 0 0 0 1 y = 1×7 logical array 0 0 0 0 0 0 1

Matrix index is out of range for deletion. Error in NaN_window_delete (line 14) y(i-1:i+1) = [] Error in Test4 (line 3) assert(isequal(NaN_window_delete(x),y_correct))