Replace zeros with NaN's - when there are already NaN's in the matrix?
Afficher commentaires plus anciens
Hi
I have a large square matrix which is made up of smaller square matrices which have some NaN values. I used 'blkdiag' to combine the matrices diagonally and all the gaps were filled in with zeros.
I now wish to replace all of the zeros in the large matrix (F) with NaN's.
I tried F(find(~F))=NaN but I get an error saying NaN's cannot be converted to logicals, which makes sense but now I'm not sure how I can get round it. I am fairly new to Matlab.
Any help would be much appreciated.
Réponse acceptée
Plus de réponses (2)
Ivan van der Kroon
le 9 Juin 2011
Change to double first:
F=double(F);
F(find(~F))=NaN;
Just curious; why would you need this?
1 commentaire
Sean de Wolski
le 9 Juin 2011
One use could be to have them show up blank in mesh or surf.
Andrei Bobrov
le 9 Juin 2011
F(~isnan(F))=NaN;
2 commentaires
Sean de Wolski
le 9 Juin 2011
That'll switch the whole matrix to nans, not just zero values.
Andrei Bobrov
le 9 Juin 2011
Oops! my bug...
Thanks Sean!
Catégories
En savoir plus sur NaNs dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!