How to find column and row indexes of items that are +-inf or Nan ?
14 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
tci27
le 18 Juil 2013
Réponse apportée : rui gao
le 25 Nov 2018
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
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 18 Juil 2013
Modifié(e) : Azzi Abdelmalek
le 18 Juil 2013
A=[inf 1 4 nan;4 -inf 2 nan]; % Example
[ii,jj]=find(isnan(A)| isinf(A))
You can also use logical indexing, which is faster
idx=isnan(A)| isinf(A)
Plus de réponses (2)
Jos (10584)
le 18 Juil 2013
Modifié(e) : Jan
le 18 Juil 2013
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 commentaires
rui gao
le 25 Nov 2018
Hi. If I need omit these elements (inf) to calculate the variance, how to achieve it?
0 commentaires
Voir également
Catégories
En savoir plus sur Elementary Math dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!