How to measure the distance between 2 sets of points.
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jim Lehane
el 4 de Mzo. de 2013
Editada: udara darshana panamulle arachchige
el 10 de Dic. de 2018
I was wondering how I measure the distance between 2 sets of coordinates.
I have 2 matrices where each matrix (X and Y) have the same number of rows (m x 2). I calculated out the distance from every point in X to every point in Y using the pdist2 tool. This gave me a m x m matrix of distances.
I want the minimum distance between X and Y where each coordinate is in a 1-to-1 ratio between X and Y. I am not sure how to separate the distances out of the pdist2 tool to discrete sets.
Does anyone know how to do this or where I can find the answer?
2 comentarios
Respuesta aceptada
Matt J
el 4 de Mzo. de 2013
Editada: Matt J
el 4 de Mzo. de 2013
m=3;
Q=perms(1:m).';
P=repmat((1:m).',1,size(Q,2));
idx=sub2ind([m,m],P,Q);
result = min(sum(DistMatrix(idx)))
5 comentarios
udara darshana panamulle arachchige
el 10 de Dic. de 2018
Editada: udara darshana panamulle arachchige
el 10 de Dic. de 2018
I have a same qustion but data set size is bit larger A(15,3) and B(105,3)
using this method gives a error due to exceeding maximum array size.
Q=perms(1:15).'; %% here I get the error
P=repmat((1:103).',1,size(Q,2));
idx=sub2ind([15,103],P,Q);
result = min(sum(DistMatrix(idx)));
ps: my qustion is same with Jim Lehane
Más respuestas (1)
Azzi Abdelmalek
el 4 de Mzo. de 2013
Editada: Azzi Abdelmalek
el 4 de Mzo. de 2013
M1 & M2 are your two matrices
M1=rand(10,2);
M2=rand(10,2)
dist=sqrt((M2(:,1)-M1(:,1)).^2+(M2(:,2)-M1(:,2)).^2)
min_dist=min(dist)
13 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!