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
MATLAB: 0x1 matrix getting while using find function
0x1 empty double matrix
Related Solutions
"Why this x == g gave me logic 0?"
Simply because those values are NOT the same.
The values that you are trying to compare cannot be exactly represented using binary floating point numbers. 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 values 0.1 or 0.001. 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 0.1 is 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.
To compare floating point values always compare the absolute difference against a tolerance:
abs(A-B)<tol
You need to learn about the limits of floating point numbers. Start by reading these:
This is worth reading as well:
"Problem with Less than or Equal to Operator"
Nope, there is no problem with the eq operator. All you have discovered is that two different binary floating point numbers are different, and that you should never test for equality of binary floating point numbers.
Always compare the difference of floating point numbers against a tolerance:
abs(A-B)<=tol
"How come this is possible?"
The value that you are trying to compare cannot be exactly represented using binary floating point numbers. 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 0.001. 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 0.001 is displayed tells you nothing about the "real" floating point number's value.
You need to learn about the limits of floating point numbers. Start by reading these:
This is worth reading as well:
Related Question
- Two equal numbers are not equal
- Error using zeros Size inputs must be integers.
- Didn’t I get “Hello” word by running following script? if I change the value in if loop except 13.2 it gives me correct answer.
- Unexpected for loop behaviour
- Find(vector==value) not working
- Find function cannot find the value
Best Answer