For Loop for finding distance between 9 centroids

1 visualización (últimos 30 días)
Harry
Harry el 30 de Mzo. de 2017
Respondida: Image Analyst el 31 de Mzo. de 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.)

Respuestas (1)

Image Analyst
Image Analyst el 31 de Mzo. de 2017
Try pdist2:
distances = pdist2(xy, xy);
where xy is an N by 2 list of x,y coordinates.

Categorías

Más información sobre Dimensionality Reduction and Feature Extraction en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by