Hello, I am using matlab 2019a and I am trying to sort points based on comparing the distance between them. I use the pdist2 function to calculate the the distance between the points stored in matricies. One matrix has 2 sets of coordinates
A= [0 0, -5.52181708330649 5.78874218621840]
the other has 7 sets
B = [38.8197976955836 -29.0434116907097-37.0532684880158 0.644925865563445-4.49735986053992 57.3402937422674-43.7442096431328 38.593514426255041.5359946082739 41.469633209806757.3572679057450 8.87552592324304-29.8320366435934 -43.1286701525403]
After calculating the distance between each point in A and every point in B i end up with a 2×7 matrix C. C(1,1) is the distance between the first point in A and the first point in B while C(2,1) is the distance between point 2 in A and point 1 in B. I want to compare each of these distances between C(1,2) to C(2,2)…. to the end and sort the points in B based on which point in A they are closest to. I hope to end up with a matrix of points closest to the first point in A and another matrix of points closest to the second point in A. If the code works with a variable number of points in A that would be greatly apprecitated. Thanks for the help.
Best Answer