Find Function gives empty matrix

a=0:0.1:90;
V=find(a==3.4);
so when i type in the above code, it should give me the indice of where a=3.4, but instead, V is an empty matrix.
but if i try to find V=find(a==3.5), it works well...
i know this may due to tolerance and accuracy stuffs...but is there a quick way to fix this ?
Thank you for your help!

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 4월 20일

0 개 추천

a=0:0.1:90
V=find(a==0.1*34)

댓글 수: 4

Jay
Jay 2013년 4월 20일
Thank you ! but could you please tell me how come it worked for 3.5 but not for 3.4?
Azzi Abdelmalek
Azzi Abdelmalek 2013년 4월 20일
편집: Azzi Abdelmalek 2013년 4월 20일
0.1 and 3.4 are saved in memory with a certain precision, it's not obvious that 0.1*34 and 3.4 will be exactly equal. try:
3.4-0.1*34
It happens that they are equal
3.5==0.1*35
Jay
Jay 2013년 4월 20일
thank you !
You can also use
tol=0.00001
V=find(abs(a-3.4)<tol)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

Jay
2013년 4월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by