choose data points that nears each other and store in different matrix
3 views (last 30 days)
I have a matrix A that has dimension n x 2.
A(:,1) is x-values and A(:,2) is y values.
Choose the the pairs that is near each others within certain distance and store in matrix B that has x value in column 1 and y value in column 2.
A= [1 1 ; 2 2 ; 5 5 ; so on]
let say if the distance we want to set is 2
then dist =sqrt((2-1)^2 +(2-1)^2) = sqrt(2) which is less than 2. So first and second pair are close.
store it in B
B= [1 1 ; 2 2; so on ]
Nothe this is example for 3 pairs and I have n- pair.
Please help me with a loop to do n-pair
Matt Kindig on 17 Jul 2013
Edited: Matt Kindig on 17 Jul 2013
One (non-loop) way:
D = sqrt((x1-x2).^2+(y1-y2).^2); %distance matrix
setDistance = 2;
[r,c]=find(D <= setDistance); %find which pairs are below setDistance.
B = [r,c]; %set of pairs
B(r==c,:)= ; %eliminate points paired with itself.