how to calculate distance of points
1 view (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Andrei Bobrov
on 16 Jul 2013
Edited: Andrei Bobrov
on 16 Jul 2013
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));
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!