Search code examples
matlabuniquedistance

matlab - minimum euclidian distances between unique pais of points of two structures


I have this distance matrix between 6 points of one structure and 5 points of the second structure:

a = [2.565  0.394   2.927   2.774   1.600;
    0.402   1.950   3.272   2.086   0.985;
    2.965   3.250   1.720   0.841   2.305;
    2.797   2.050   0.830   0.829   1.585;
    3.865   2.662   1.246   2.086   2.634;
    1.592   0.977   2.305   1.579   0.274]

I need the minimum distances between points. Sometimes I get one point between two points of the other structure. 0.274 0.394 0.402 0.830 0.829 This means I will get point 4 (from the 6 points structure) to be closest to points 3 and 4 from the other structure. I am not allowed to have one point closest to two others. How do I get unique pairs of these close points? I think I should verify if there is a small difference between first 2 minima in a row. The problematic point is always in the middle of other two. I need to get 0.274 0.394 0.402 0.830 0.841 (see answer 1). My original code was:

for i = 1 : 6
    mins(i) = min(a(i, :));
end
mins = sort(mins);
mins = mins(1 : 5);

Thanks.


Solution

  • So thanks beaker, I do hope the question gets another answer,

    [pairs,a1,a2]=matchpairs(a,1,'min')
    pairs =
         2     1
         1     2
         4     3
         3     4
         6     5
    a1 =
         5
    a2 =
      0×1 empty double column vector
    

    Also I hope someone explains what the other outputs mean and when can they be useful.