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 件のコメント

KSSV
KSSV 2018 年 5 月 2 日
Read about dist. You can write your own formula for this not a deal.
Jan
Jan 2018 年 5 月 2 日
The distance to what?
Lu Zhang
Lu Zhang 2022 年 5 月 4 日
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.

サインインしてコメントする。

 採用された回答

Jan
Jan 2018 年 5 月 2 日
編集済み: Jan 2018 年 5 月 2 日

2 投票

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 件のコメント

Nurul Atifah
Nurul Atifah 2018 年 5 月 2 日
編集済み: Nurul Atifah 2018 年 5 月 2 日
I had try using the last code you give. And it can calculate my data. I just want to know is it wrong if im using out = squareform(pdist(A)) ? This is to calculate the face point distance between point to another point.
Jan
Jan 2018 年 5 月 2 日
pdist calculates the pairwise distances between all points of the set. Is this what you want? You still did not mention, which distance you want to obtain.
Nurul Atifah
Nurul Atifah 2018 年 5 月 2 日
編集済み: Nurul Atifah 2018 年 5 月 2 日
I want to calculate distance between a set of points to another set of points. Let say I have 83 x 3 points. I want to calculate the euclidean distance of the points. Did my explaination is well enough? Sorry if im bad at explaining. I will try my best. Btw, thank you for helping me.
Jan
Jan 2018 年 5 月 3 日
No, this is still not clear. In the first sentence you mention two different sets of points. Afterwards you tell us, that one set is [83 x 3]. And the other set? I've posted the code for calculating the distances between a set of points and one additional point. With a simple loop, you can expand this to two sets.
Nurul Atifah
Nurul Atifah 2018 年 5 月 4 日
Sorry for my bad explaining. Okay, to have better view. I would like to calculate the euclidean distance as follows:
Eg,
x y z
3 4 5 --> 1st point
7 8 9 --> 2nd point
Therefore, I want to calculate between 1st point and 2nd point.
Jan
Jan 2018 年 5 月 5 日
M = [3,4,5; ...
7,8,9];
v = M(1, :) - M(2, :);
dist = sqrt(sum(v .^ 2))
Nurul Atifah
Nurul Atifah 2018 年 5 月 6 日
Ohh I see. Thats exactly what I want. Thank you so much. :)
Dee
Dee 2019 年 10 月 8 日
Hi Nurul were you able to find for 83 by 3 matrix?

サインインしてコメントする。

その他の回答 (1 件)

dmitry luchinsky
dmitry luchinsky 2019 年 9 月 17 日

0 投票

why not to use pdist2?

カテゴリ

質問済み:

2018 年 5 月 2 日

コメント済み:

2022 年 5 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by