How to handle 'NaN' values

em try to write code to find 'Interpolation error' but in Error metrix there occuring NaN at many place, even i have converted them in 'double()' now i want NaN value would replace by '0'or by its right value, Instead of NaN. plz help me . em trying to fix it bt it doesn't work.
{double(errors);
for i=1:1:size(errors, 1) for j=1:1:size(errors, 2) if errors(i, j)== 'NaN' errors(i, j)=0; else errors(i, j)=(errors(i, j)); end} end end this code is not working... i want not to occur ant NaN value during code processing. . . how do i write a code to avoide from such unwanted values. . .

 채택된 답변

Paulo Silva
Paulo Silva 2011년 3월 31일

4 개 추천

errors(isnan(errors))=0

댓글 수: 1

Jan
Jan 2011년 3월 31일
And one vote for the correct answer reduced to the necesary minimum.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2011년 3월 31일

4 개 추천

This cannot work:
if errors(i, j)== 'NaN'
"error(i, j)" is a scalar DOUBLE, 'NaN' is a [1 x 3] CHAR vector, also known as "string". Even this would fail:
if errors(i, j) == NaN
because IEEE conventions state, that a comparison to NaN replies FALSE ever:
1 < NaN % >> 0
1 == NaN % >> 0
1 > NaN % >> 0
NaN == NaN % >> 0
Therefore isnan() must be used as shown in Paulo's answer.

댓글 수: 2

Talat
Talat 2011년 3월 31일
oh Thanks guy. . .
Paulo Silva
Paulo Silva 2011년 3월 31일
+1 vote for such detailed answer :)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interpolation of 2-D Selections in 3-D Grids에 대해 자세히 알아보기

태그

질문:

2011년 3월 31일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by