Replace NaN with specific value.
34 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mehul Agrawal
le 27 Juin 2016
Commenté : Steven Lord
le 27 Juin 2016
I have many large column matrices (each is ~20k x 1). Some elements of the matrices are NaN. I want to replace them with 0 (or some number). Is there a quick way for that. Looping through each element is a very inefficient process and delays my program. The help is really appreciated.
0 commentaires
Réponse acceptée
Guillaume
le 27 Juin 2016
Modifié(e) : Guillaume
le 27 Juin 2016
yourmatrix(isnan(yourmatrix)) = somevalue;
But, using NaN to mark exceptional values is much better than using 0 or some other special value.
2 commentaires
Steven Lord
le 27 Juin 2016
For a couple releases now the sum function has accepted a flag that lets you specify whether NaN values should be included in the sum (which makes the sum NaN) or excluded (unless all the values being summed are NaN.)
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!