how to write an if statement for a matrix with some NaN elements?
2 ビュー (過去 30 日間)
古いコメントを表示
Hello all,
I have a matrix with some elements 0s or 1s and the rest are NaNs. I would like to write an if statement that ignores the NaN elements of the matrix. I have tried
if (a(:)==1 or a(:)==0)
------------
end
however, I am getting an error. I would appreciate if somebody can help me please. Thanks.
回答 (1 件)
Walter Roberson
2015 年 5 月 5 日
nonnanlocs = ~isnan(a);
a(nonnanlocs) = SomeFunction(a(nonnanlocs));
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!