Problem 690. Remove the two elements next to NaN value
The aim is to remove the two elements next to NaN values inside a vector.
For example:
x = [6 10 5 8 9 NaN 23 9 7 3 21 43 NaN 4 6 7 8]
The output y will be:
y = [6 10 5 8 9 7 3 21 43 7 8]
Nan values and the 2 next elements after the NaN (23-9 and 4-6) have been removed.
There will be always NaN values in the input vector followed by at least 2 integers.
Solution Stats
Problem Comments
-
6 Comments
The term "next to NaN" would generally be considered as the one right before and the one right after NaN, if existing. Also the problem failed to say that NaN themselves need to be removed.
JF & LD, I agree with both of your comments. Furthermore, it is unfortunate that in the example the first NaN has digit "9" both immediately preceding it and two elements after it, making the procedure to get the result in that neighbourhood ambiguous.
not so easy problem. Took a lot of time for thinking!
Solution Comments
Show commentsProblem Recent Solvers663
Suggested Problems
-
Remove any row in which a NaN appears
8675 Solvers
-
Read a column of numbers and interpolate missing data
2330 Solvers
-
Project Euler: Problem 9, Pythagorean numbers
1312 Solvers
-
Get the elements of diagonal and antidiagonal for any m-by-n matrix
487 Solvers
-
Who has power to do everything in this world?
462 Solvers
More from this Author30
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!