Cody

# Problem 42669. replace nan values iteratively.

Solution 3329093

Submitted on 22 Oct 2020 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 = [2; 4; 6; nan; nan; nan; 10]; y_correct = [2; 4; 6; 8; 9; 9.5; 10]; assert(isequal(replaceNaN(x),y_correct))

m = 8 x = 2 4 6 8 NaN NaN 10 m = 9 x = 2 4 6 8 9 NaN 10 m = 9.5000 x = 2.0000 4.0000 6.0000 8.0000 9.0000 9.5000 10.0000

2   Pass
x = [1; 2; 3; 4; nan; 6]; y_correct = [1; 2; 3; 4; 5; 6]; assert(isequal(replaceNaN(x),y_correct))

m = 5 x = 1 2 3 4 5 6

3   Pass
x = [360; nan; nan; nan; nan; 120]; y_correct = [360; 240; 180; 150; 135; 120]; assert(isequal(replaceNaN(x),y_correct))

m = 240 x = 360 240 NaN NaN NaN 120 m = 180 x = 360 240 180 NaN NaN 120 m = 150 x = 360 240 180 150 NaN 120 m = 135 x = 360 240 180 150 135 120

4   Pass
x = [2; 4; 6; nan; nan; nan; 10; 360; nan; nan; nan; nan; 120]; y_correct = [2; 4; 6; 8; 9; 9.5; 10; 360; 240; 180; 150; 135; 120]; assert(isequal(replaceNaN(x),y_correct))

m = 8 x = 2 4 6 8 NaN NaN 10 360 NaN NaN NaN NaN 120 m = 9 x = 2 4 6 8 9 NaN 10 360 NaN NaN NaN NaN 120 m = 9.5000 x = 2.0000 4.0000 6.0000 8.0000 9.0000 9.5000 10.0000 360.0000 NaN NaN NaN NaN 120.0000 m = 240 x = 2.0000 4.0000 6.0000 8.0000 9.0000 9.5000 10.0000 360.0000 240.0000 NaN NaN NaN 120.0000 m = 180 x = 2.0000 4.0000 6.0000 8.0000 9.0000 9.5000 10.0000 360.0000 240.0000 180.0000 NaN NaN 120.0000 m = 150 x = 2.0000 4.0000 6.0000 8.0000 9.0000 9.5000 10.0000 360.0000 240.0000 180.0000 150.0000 NaN 120.0000 m = 135 x = 2.0000 4.0000 6.0000 8.0000 9.0000 9.5000 10.0000 360.0000 240.0000 180.0000 150.0000 135.0000 120.0000

5   Pass
x = [2; nan; 4; 10; nan; 12; -20; nan; -40]; y_correct = [2; 3; 4; 10; 11; 12; -20; -30; -40]; assert(isequal(replaceNaN(x),y_correct))

m = 3 x = 2 3 4 10 NaN 12 -20 NaN -40 m = 11 x = 2 3 4 10 11 12 -20 NaN -40 m = -30 x = 2 3 4 10 11 12 -20 -30 -40

6   Pass
x = [2; nan; nan; 6]; y_correct = [2; 4; 5; 6]; assert(isequal(replaceNaN(x),y_correct))

m = 4 x = 2 4 NaN 6 m = 5 x = 2 4 5 6

7   Pass
x = [2; nan; 8; 10; nan; 12; -20; nan; -40]; y_correct = [2; 5; 8; 10; 11; 12; -20; -30; -40]; assert(isequal(replaceNaN(x),y_correct))

m = 5 x = 2 5 8 10 NaN 12 -20 NaN -40 m = 11 x = 2 5 8 10 11 12 -20 NaN -40 m = -30 x = 2 5 8 10 11 12 -20 -30 -40

### Community Treasure Hunt

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

Start Hunting!