how to calculate distance of points

1 次查看(过去 30 天)
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.

采纳的回答

Andrei Bobrov
Andrei Bobrov 2013-7-16
编辑:Andrei Bobrov 2013-7-16
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));

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by