How could i know if there's still NaN in a matrix?

1 visualización (últimos 30 días)
Isti el 29 de Abr. de 2012
For example, i have a matrix like this: A:
2 1 4 5 2
3 4 5 6 2
5 3 NaN 3 NaN
4 2 1 9 3
7 1 8 2 4
My pseudocode is like this:
while there's still NaN in a matrix A
%i will do the process here to fill the Nan
then, this process will stop until there's no NaN in matrix A again.
What to do? Thanks before :')

Respuestas (1)

Walter Roberson
Walter Roberson el 29 de Abr. de 2012
hasnan = any(isnan(A(:)));
while hasnan
%fill a nan at this point
hasnan = any(isnan(A(:)));
In your earlier version of this question (which you deleted after I responded :( ) you were filling the NaN with a constant value, 10 in your example. If all of the NaN are to be filled with the same value, then the code can be simplified to
A(isnan(A)) = TheConstantValue;
  4 comentarios
Isti el 30 de Abr. de 2012
ok. thank you. i can get it now :)

Iniciar sesión para comentar.


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


Community Treasure Hunt

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

Start Hunting!

Translated by