MATLAB: How to calculate distance of points

distancematrix

Hi, leenda here. I am new to this programming thingy.
I have a set of 150 data containing values of (xi,yi). How to I find the distance of these data and tabulate the distance in a matrix.
Example:
I have points P1, P2, … P150.
How do I calculate the distance of P1 to P2, P1 to P3, P1 to P4 , etc …
Thanks a lot. Your help is much appreciated.

Best Answer

P - your data containing values of (xi,yi). < 150 x 2 double >
P = randi(250,150,2); % eg
out = pdist(P);
in table form:
out = squereform(pdist(P));
OR
outtableform = squeeze(sqrt(sum(bsxfun(@minus,P,permute(P,[3 2 1])).^2,2)));
outvectorform = nonzeros(tril(outtableform));