Replacing NaN with its succeeding values
Show older comments
I have an array which should replace the NaN with its succeeding value. For example:
A=[NaN NaN 1 1 0 0 NaN 0 NaN 1 1]
then output should be
B=[1 1 1 1 0 0 0 0 1 1 1].
Can someone please help me with this?
Accepted Answer
More Answers (1)
Andrei Bobrov
on 2 Aug 2016
A=[NaN NaN 1 1 0 0 NaN 0 NaN 1 1];
z = flip(A(:));
x = ~isnan(z);
z = z(x);
B = flip(z(cumsum(x)))';
Categories
Find more on Image Arithmetic 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!