MATLAB: Ismembertol not working correctly

ismemberMATLAB

I have two matrices A and B in the attached xls file and run
[~,loc3] = ismembertol(A(:,2),B(:,1),0.01);
and the outcome loc3 also in the xls file. This is not right since loc3 taking values other than 0 and 1. Please advise.

Best Answer

Only the first output of ismember or ismembertol is a logical array. The second output, the one you are asking for, according to the documentation:
  • LIA = ismembertol(A,B,tol) returns an array containing logical 1 (true) where the elements of A are within tolerance of the elements in B.
  • [LIA,LocB] = ismembertol(A,B,tol) also returns an array, LocB, that contains the index location in B for each element in A that is a member of B.
So the second output is an array of indices (similar to what you would get from the find function), rather than the logical array produced by the first output.