For Loop for finding distance between 9 centroids

1 Ansicht (letzte 30 Tage)
Harry
Harry am 30 Mär. 2017
Beantwortet: Image Analyst am 31 Mär. 2017
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.)

Antworten (1)

Image Analyst
Image Analyst am 31 Mär. 2017
Try pdist2:
distances = pdist2(xy, xy);
where xy is an N by 2 list of x,y coordinates.

Kategorien

Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by