How to replace elements different than 0 and different than NaN to 1?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
cfjunior
am 24 Okt. 2013
Kommentiert: cfjunior
am 24 Okt. 2013
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?
0 Kommentare
Akzeptierte Antwort
Mohammad Monfared
am 24 Okt. 2013
Let the matrix name, A, so this is done by:
A(xor((A~=0),isnan(A))) = 1 ;
Weitere Antworten (1)
Azzi Abdelmalek
am 24 Okt. 2013
Bearbeitet: Azzi Abdelmalek
am 24 Okt. 2013
A(A~=0)=1
%or maybe you want
idx=isnan(A) | A==0
A(~idx)=1
3 Kommentare
Azzi Abdelmalek
am 24 Okt. 2013
Bearbeitet: Azzi Abdelmalek
am 24 Okt. 2013
Ok, then just run the second code
idx=isnan(A) | A==0
A(~idx)=1
Siehe auch
Kategorien
Mehr zu NaNs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!