MATLAB: Ismembertol does not work as documented

ismembertol

Hello,
This function should work with absolute tolerance. Here is an example where it doesn't work as documented
B=[ 1.9500 1.0000];
A=[3.0000 2.0000 4.0000 2.5000 1.2000 1.1000];
[Loc1,Loc2]=ismembertol(B,A,0.1,'DataScale',1)
What should come out according to documentation is
Loc1 =
1×2 logical array
1 1
Loc2 =
2 6
What does come out however is
Loc1 =
1×2 logical array
1 0
Loc2 =
2 0
It seems someone forgot the absolute when comparing 🙂

Best Answer

The documentation isn't wrong. You've set a tolerance that can only satisfied reliably at A(6) in infinite precision arithmetic. Observe:
>> [Loc1,Loc2]=ismembertol(B,A,0.1+eps,'DataScale',1)
Loc1 =
1×2 logical array
1 1
Loc2 =
2 6