Calculate distances between data points
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mani Ahmadian
el 14 de Dic. de 2014
Comentada: matt dash
el 15 de Dic. de 2014
Hi
I have 6 separated groups(as g1,g2,g3,..., g6) and each of them have some spatial data points as (x,y,z,k) where x,y,z determine position of each data point and k is its value, for example Temperature value at that point.
Note that the number of data points in each group is not equal.
I want to calculate distances between data points in each group and other data points in other groups.
Would you please guide me to solve my problem?
Thanks a lot.
Mani
2 comentarios
Guillaume
el 14 de Dic. de 2014
So do you want the distance between all of the points in one group and all of the points in another group, that is size(g1, 1) * size(g2, 1) distances, or something else?
Respuesta aceptada
Guillaume
el 14 de Dic. de 2014
Possibly, this is what you want:
g1 = randi([-100 100], 5, 4); %example data, a 5*4 matrix
g2 = randi([-100 100], 3, 4); %example data, a 3*4 matrix
[idx1, idx2] = ndgrid(1:size(g1, 1), 1:size(g2, 1)); %row indices to calculate distance between
distance = arrayfun(@(row1, row2) norm(g2(row2, 1:3) - g1(row1, 1:3)), idx1, idx2)
Each row in the output matrix correspond to a row of g1, and each column to a row of g2. For example, the value at row 3, column 2 is the distance between row 3 of g1 and row 2 of g2.
2 comentarios
matt dash
el 15 de Dic. de 2014
Look on the file exchange for the file named "IPDM" http://www.mathworks.com/matlabcentral/fileexchange/18937-ipdm--inter-point-distance-matrix ... it does what you need and it is very fast:
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Distribution Plots 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!