For Loop for finding distance between 9 centroids
1 次查看(过去 30 天)
显示 更早的评论
I would like to find the distance between 9 data points in a neat way.
I tried to do it in a for loop but that didn't work out.
Any help is appreciated.
An example of what I'm trying to do is given below:
A = [5,2];
B = [3,2];
C = [4,5];
D = [6,9];
E = [7,7];
F = [3,2];
G = [9,8];
H = [1.5,1.7];
I = [2.5,3.2];
X = [A;B];
Y = [A;C];
Z = [B;C];
.
.
.
pdist(X);
pdist(Y);
pdist(Z);
.
.
.
It should tell me the distance between any of these data points.
I'm trying to find the smallest distance between any of these variables.
(To be excluded: A vs A, B vs B etc.) (To be included: A vs all, B vs all etc.)
0 个评论
回答(1 个)
Image Analyst
2017-3-31
Try pdist2:
distances = pdist2(xy, xy);
where xy is an N by 2 list of x,y coordinates.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!