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

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 :')

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 4 月 29 日

0 投票

hasnan = any(isnan(A(:)));
while hasnan
%fill a nan at this point
hasnan = any(isnan(A(:)));
end
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 件のコメント

Isti
Isti 2012 年 4 月 29 日
i'm sorry before. because there's something error in my internet connection before :( actually i'm really thankful for your answer :)
for your previous answer: A(isnan(A)) = TheConstantValue;
it doesn't suitable for my process.
then, i'll try your solution above. anyway, i still thanks :)
Isti
Isti 2012 年 4 月 29 日
it comes into looping forever when i try it :(
Walter Roberson
Walter Roberson 2012 年 4 月 29 日
If it is looping forever then you have not filled in at least one nan at the place I put the comment; my comment corresponds to your pseudocode "%i will do the process here to fill the Nan".
Isti
Isti 2012 年 4 月 30 日
ok. thank you. i can get it now :)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

質問済み:

2012 年 4 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by