Replace NaNs with the number that appears to its left in the row. - MATLAB Cody - MATLAB Central

Problem 73. Replace NaNs with the number that appears to its left in the row.

Difficulty:Rate

Replace NaNs with the number that appears to its left in the row.

If there are more than one consecutive NaNs, they should all be replaced by the first non-NaN value to the immediate left of the left-most NaN. If the NaN is in the first column, default to zero.

For example, if

x = [NaN  1   2  NaN NaN 17  3  -4 NaN]

then

y = [ 0   1   2   2   2  17  3  -4  -4]

Solution Stats

52.5% Correct | 47.5% Incorrect
Last Solution submitted on Feb 24, 2025

Problem Comments

Solution Comments

Show comments
Primes and Rough Numbers, Basic ideas
What is a rough number? What can they be used...
2
4

Problem Recent Solvers3010

Suggested Problems

More from this Author96

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page