0x1 matrix getting while using find function

조회 수: 39 (최근 30일)
Sandeep Nair
Sandeep Nair 2018년 9월 10일
댓글: Sandeep Nair 2018년 9월 10일
Am getting 0x1 matrix while using find function to retreiv the indices,i have tried to use the max function in the array and then used find function still getting 0x1 empty double matrix error.Could you please help as when am using the same function to retriev the other indices am getting proper results
  댓글 수: 6
Stephen23
Stephen23 2018년 9월 10일
편집: Stephen23 2018년 9월 10일
You are doing an exact comparison of floating point numbers, which is not recommend because of the exact problem that you are having. Always compare the difference of floating point numbers against a tolerance:
abs(A-B)<=tol
The values that you are trying to compare cannot be exactly represented using binary floating point numbers, and are not the same. What you see printed in the command window is the closest representation to 5 or 16 significant digits, depending on your current format setting. To see the "real" value download James Tursa's FEX submission:
Use James Tursa's num2strexact and you will see that none of those values really have the exact value 2.11. All you are looking at is a representation of those floating point numbers displayed in the command window, to the precision defined by your format setting. Just because you see 2.11 displayed tells you nothing about the "real" floating point number's value.
Note that you can change how the value is displayed by changing the format.
You need to learn about the limits of floating point numbers. Start by reading these:
This is worth reading as well:
Sandeep Nair
Sandeep Nair 2018년 9월 10일
thanks for the answer,i applied it in my code and its running fine

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

채택된 답변

the cyclist
the cyclist 2018년 9월 10일
My best guess here, with the limited information you have given, is that you are trying to compare a number to one that is not exactly equal, due to floating point representation.
Take a look at this question/answer for more details.
  댓글 수: 3
Sandeep Nair
Sandeep Nair 2018년 9월 10일
Hi, I looked at the answer and have already applied these solutions to my code but still its not working. Please note i have set of datasets lets say 0 to 1000 each is getting incremented by 0.01 and i want to look at the indices of value 2.11 ,my code is working perfectly for other values like eg value of 2.12 but at some points,the code is not working properly and am getting 0x1 empty double column vector
Guillaume
Guillaume 2018년 9월 10일
Clearly, you've not read properly the answers (also look at Stephen's comment) or not doing the comparison properly. You need to understand that you cannot use == to compare floating point numbers. It's easy to demonstrate that it does not work:
a = 2.09 + 0.01 + 0.01 %display 2.11 but is not actually 2.11 due to floating point precision
a == 2.11 %return false
a - 2.11 %display about -4.4e-16
tolerance = 1e-6 %appropriate tolerance for the magnitude of numbers being compared
abs(a - 2.11) < tolerance %proper way to compare floating point number

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by