Cody

Problem 300. Remove NaN ?

Solution 2954047

Submitted on 16 Sep 2020 by Catherine Jones
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))

check_nan = 3×3 logical array 0 0 0 1 0 1 0 0 0 sum_rows = 0 2 0 count = 1 y = [] y = 8 1 6 count = 2 y = 8 1 6 4 9 2 count = 3

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

check_nan = 4×5 logical array 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 sum_rows = 0 0 1 1 count = 1 y = [] y = 16 2 3 13 1 count = 2 y = 16 2 3 13 1 5 11 10 8 1 count = 3

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

check_nan = 4×4 logical array 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 sum_rows = 0 0 1 0 count = 1 y = [] y = 1 1 1 1 count = 2 y = 1 1 1 1 1 1 1 1 count = 3 y = 1 1 1 1 1 1 1 1 1 1 1 1 count = 4

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

check_nan = 2×1 logical array 0 1 sum_rows = 0 1 count = 1 y = [] y = 1 count = 2

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

check_nan = logical 1 sum_rows = 1 count = 1 y = []

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

check_nan = 1×11 logical array 0 0 0 0 0 0 0 0 0 0 1 sum_rows = 1 count = 1 y = []

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

check_nan = 11×1 logical array 0 0 0 0 0 0 0 0 0 0 1 sum_rows = 0 0 0 0 0 0 0 0 0 0 1 count = 1 y = [] y = 1 count = 2 y = 1 2 count = 3 y = 1 2 3 count = 4 y = 1 2 3 4 count = 5 y = 1 2 3 4 5 count = 6 y = 1 2 3 4 5 6 count = 7 y = 1 2 3 4 5 6 7 count = 8 y = 1 2 3 4 5 6 7 8 count = 9 y = 1 2 3 4 5 6 7 8 9 count = 10 y = 1 2 3 4 5 6 7 8 9 10 count = 11

Suggested Problems

More from this Author10

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!