From: asd on
I have two arrays not of the same size. They contain floating point data. I was wondering if there was anyway to find out the number of common elements between the 2 arrays but with a certain threshold. Say for example if my threshold is 0.05 and one array contains 0.4 and the other 0.45 it should be considered as a match. Is there any way to this?
Thank you in advance
Vivek
From: Darren Rowland on

Try the function ismemberf from the FEX
http://www.mathworks.com/matlabcentral/fileexchange/23294-ismemberf

Darren
From: Jan Simon on
Dear Vivek!

> I have two arrays not of the same size. They contain floating point data. I was wondering if there was anyway to find out the number of common elements between the 2 arrays but with a certain threshold. Say for example if my threshold is 0.05 and one array contains 0.4 and the other 0.45 it should be considered as a match. Is there any way to this?

Besides Bruno's excellent ismemberf, you can do this with this simple solution also:

------------------------------------- 8<---------------------------
function n = nMemberTol(A, B, Tol)
% Jan Simon, 15-Mar-2009
n = 0;
B = B(:);
for iA = 1:numel(A)
if any(abs(B - A(iA)) <= Tol)
n = n + 1;
end
end

return;
---------------------------------------------------->8--------------------

Good luck, Jan