How to replace elements different than 0 and different than NaN to 1?
Mostrar comentarios más antiguos
I have this huge matrix with a lot of elements: (i) equal to zero; (ii) number different than zero; (iii) NaN values ...
I need to replace all the the NUMBERS different than 0 to 1.
How do I do it not replacing the NaN values?
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 24 de Oct. de 2013
Editada: Azzi Abdelmalek
el 24 de Oct. de 2013
A(A~=0)=1
%or maybe you want
idx=isnan(A) | A==0
A(~idx)=1
3 comentarios
cfjunior
el 24 de Oct. de 2013
Azzi Abdelmalek
el 24 de Oct. de 2013
Editada: Azzi Abdelmalek
el 24 de Oct. de 2013
Ok, then just run the second code
idx=isnan(A) | A==0
A(~idx)=1
cfjunior
el 24 de Oct. de 2013
Categorías
Más información sobre NaNs en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!