Euclidean distance for 3D data

83 visualizzazioni (ultimi 30 giorni)
Nurul Atifah
Nurul Atifah il 2 Mag 2018
Commentato: Lu Zhang il 4 Mag 2022
Hye, can anybody help me, what is the calculation to calculate euclidean distance for 3D data that has x,y and z value in Matlab? Thank you so much. Really appreciate if somebody can help me.
  3 Commenti
Jan
Jan il 2 Mag 2018
The distance to what?
Lu Zhang
Lu Zhang il 4 Mag 2022
Hi, Nurul. Did you figure it out finally? Is it possible for you to share the answer? I want to compute the euclidean distance for fMRI data on the vertex level. Thank you so much.

Accedi per commentare.

Risposta accettata

Jan
Jan il 2 Mag 2018
Modificato: Jan il 2 Mag 2018
I guess, that you want the distance of a set of points to a specific other point:
% 100 points in 3D:
Pos = rand(100, 3);
% Euclidean distance to point [1,2,3]:
D = sqrt(sum((Pos - [1,2,3]).^2, 2))
With modern Matlab versions:
D = vecnorm(Pos - [1,2,3], 2, 2)
With old Matlab versions before the auto-expanding (< R2016):
V = bsxfun(@minus, Pos, [1,2,3]);
D = sqrt(sum(V.^2, 2))
  8 Commenti
Nurul Atifah
Nurul Atifah il 6 Mag 2018
Ohh I see. Thats exactly what I want. Thank you so much. :)
Dee
Dee il 8 Ott 2019
Hi Nurul were you able to find for 83 by 3 matrix?

Accedi per commentare.

Più risposte (1)

dmitry luchinsky
dmitry luchinsky il 17 Set 2019
why not to use pdist2?

Community Treasure Hunt

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

Start Hunting!

Translated by