For Loop for finding distance between 9 centroids

1 回表示 (過去 30 日間)
Harry
Harry 2017 年 3 月 30 日
回答済み: Image Analyst 2017 年 3 月 31 日
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.)

回答 (1 件)

Image Analyst
Image Analyst 2017 年 3 月 31 日
Try pdist2:
distances = pdist2(xy, xy);
where xy is an N by 2 list of x,y coordinates.

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by