How to merge adjacent NaN values into single NaN value in a vector?
Show older comments
I have [1 2 3 NaN NaN 0 1 2 NaN 9 8 7 6 NaN NaN NaN 1 1] anf I want [1 2 3 NaN 0 1 2 NaN 9 8 7 6 NaN 1 1] without a for cycle. Are there any trick to do this?
1 Comment
Stephen23
on 1 Jul 2018
@Mr M: please remember to accept answers or provide feedback on your earlier questions:
Accepted Answer
More Answers (1)
Andrei Bobrov
on 2 Jul 2018
a = [1 2 3 NaN NaN 0 1 2 NaN 9 8 7 6 NaN NaN NaN 1 1];
lo = ~isnan(a);
lo(strfind(lo,[0 1])) = true;
out = a(lo);
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!