MATLAB: How do merge two vectors into one, like in intersect. but now with a small margin

clusterintersectMATLABnoiserange

Hi,
I want to return the values common to the two vectors with no repetitions, but the data have some noise.
for example A = [ 50 100 300 500 1000 1500 1750]; B = [100 300 501 1500];
C = intersect(A,B) C = [100 300 1500]
C needs to be C = [100 300 500 1500]
Intersect will not return 501, but it needs to be returned. Is there a way where you can build in a range on which intersect will cluster these values and return them?

Best Answer

Read about ismembertol.
idx = ismembertol(A,B,10^-3) ;
C = A(idx) ;