Replace NaN with corresponding elements in another array.

23 visualizaciones (últimos 30 días)
Bob Whiley
Bob Whiley el 2 de Feb. de 2015
Comentada: James Tursa el 5 de Feb. de 2015
I can find the locations of all the NaNs in an array, but how can I replace those elements with the corresponding elements of another array.

Respuestas (1)

James Tursa
James Tursa el 2 de Feb. de 2015
A = original array with NaNs in it
B = array with desired replacement values
x = isnan(A);
A(x) = B(x);
  2 comentarios
Bob Whiley
Bob Whiley el 2 de Feb. de 2015
How can I replace the zeros in the resulting array with the corresponding elements in A?
James Tursa
James Tursa el 5 de Feb. de 2015
The zeros in what resulting array? If you have an array C the same size as A and you want to replace the zeros in C with the corresponding values from A, then use a similar technique as above. E.g.,
x = (C == 0);
C(x) = A(x);

Iniciar sesión para comentar.

Categorías

Más información sobre NaNs en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by