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
Problem Comments
1 Comment
Solution Comments
Show comments
Loading...
Problem Recent Solvers3064
Suggested Problems
-
46565 Solvers
-
Sum of first n terms of a harmonic progression
497 Solvers
-
Determine the number of odd integers in a vector
824 Solvers
-
18022 Solvers
-
Create an index-powered vector
938 Solvers
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!
The problem does not limit the array to a single row. Add a few cases of multiple rows or define as single row.