Replacing NaN with its succeeding values
Mostrar comentarios más antiguos
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?
Respuesta aceptada
Más respuestas (1)
Andrei Bobrov
el 2 de Ag. de 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)))';
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!