MATLAB: Removing far points between vectors

Hello, i have 2 very large vectors which represent points in a 3d image, im interested in removing all points from the first vector that are farther then 'distance' from the second vector. for example: let A=(1 1 1, 10 10 10, 20 20 20) and b be (1 1 1, 2 2 2, 3 3 3), and distance be 5, only point 1 1 1 in a is closer then 5 to a certain point in b therefore the result should be C=(1 1 1)

Best Answer

A=[1 1 1; 10 10 10; 20 20 20]
B = [1 1 1; 2 2 2; 3 3 3]
C = A(sqrt(sum((A-B).^2,2))<=5,:) %edited