a(a==NaN) does not find NaN's in matrix. What to do?
조회 수: 8 (최근 30일)
이전 댓글 표시
I have
a=1 NaN 2 6
I want to change the NaN to 0 but
a(a==NaN)=0
does not work and gives me
a =
1.00 NaN 2.00 6.00
What did i do wrong?
댓글 수: 0
채택된 답변
Sean de Wolski
2012년 5월 29일
NaNs are not equal to themselves!
You could thus do either of these:
* a(isnan(a))=0; %isnan
* a(a~=a) = 0; %nans aren't equal to themselves
추가 답변 (1개)
Thomas
2012년 5월 29일
Sharon, you are unable to replace the NaN because
NaN ~= NaN (in matlab NaN's are unequal) you can check this by
isequal(NaN,NaN)
ans =
0
to replace NaN's use the isnan function
doc isnan
For your example you need
a(isnan(a))=0
a =
1.00 0 2.00 6.00
참고 항목
카테고리
Help Center 및 File Exchange에서 NaNs에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!