How to find column and row indexes of items that are +-inf or Nan ?
古いコメントを表示
Hello
I have a very large matrix X where some elements can be -+inf or Nan. Currently I loop over all elements, check each one and handle it. It is taking forever. How can I easily find the [row,col] coordinates of such items ? I tried fiddling with isfinite(X) but in vain
Thanks much for any help
採用された回答
その他の回答 (2 件)
Jos (10584)
2013 年 7 月 18 日
編集済み: Jan
2013 年 7 月 18 日
Using ISFINITE is fine. You just have to negate the outcome
Here is a small example, showing all the steps:
M = [1 Inf 3 ; 11 12 NaN]
tf = isfinite(M)
tf = ~tf
[ri,ci] = find(tf)
which you can combine into a single line if you understand each step
[ri,ci] = find(~isfinite(M))
2 件のコメント
Jan
2013 年 7 月 18 日
Fixed typo: "INFINITE" => "ISFINITE".
Jos (10584)
2013 年 7 月 18 日
thanks Jan
rui gao
2018 年 11 月 25 日
0 投票
Hi. If I need omit these elements (inf) to calculate the variance, how to achieve it?
カテゴリ
ヘルプ センター および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!