array element not equal to equivalent double
조회 수: 4 (최근 30일)
이전 댓글 표시
I have the following code:
array=0.0001:0.0001:0.6;
x=0.0402
y=array(402)
test=x==y
the result of the test is 0 and I really don't understand why... Both are supposed to be double. Can somebody help?
(the final idea is to find the index of X in the array with the find function)
댓글 수: 0
채택된 답변
Matt J
2022년 11월 15일
편집: Matt J
2022년 11월 15일
Because computers cannot do exact math. The difference between x and y beyond the 4th decimal place make this clear:
array=0.0001:0.0001:0.6;
x=0.0402
y=array(402)
x-y
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!