MATLAB pdist function

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-03-19T11:53:30Z Indexed on 2010/03/19 13:41 UTC
Read the original article Hit count: 173

Filed under:

Hi,

I am using the pdist command to find the distance between x and y coordinates stored in a matrix.

X = [100 100;
      0  100;
     100  0;
     500 400;
     300 600;];

D = pdist(X,'euclidean')

Which returns a 15 element vector. :

[0.734979755525412 3.40039811339820 2.93175207511321   1.83879677592575 2.40127440268306 2.75251513299386 2.21488402640753 1.10610649500317 1.81674017301699 0.903207751535635 1.99116952754924 1.05069952386082 1.24122819418333 1.08583377275532 1.38729428638035]

Is there a way to associate these distances with the coordinates they were derived from, i.e. store them in a matrix with the general row form:

[Length xcoordinate1 ycoordinate1 xcoordinate2 ycoordinate2]

Where there is a row for each length found?

Thanks in advance

© Stack Overflow or respective owner

Related posts about matlab