# How to measure the shortest distance among different points using Matlab

2 ビュー (過去 30 日間)
M.S. Khan 2020 年 10 月 27 日
コメント済み: Jakob 2021 年 3 月 10 日
Lets suppoese i have the points as shown by B. For example, P1(1,1,2 ), P2(1,2,3 ) etc as shown by B. I want to measure the shortest distance among these points.
x = B(:,1), y =B(:,2) and z = B(:,3).
Thanks in advance for support from community members. Regards!
B =
1 1 3
1 2 3
2 3 1
2 3 2
3 1 1
3 3 1
3 3 2
##### 5 件のコメント3 件の古いコメントを表示3 件の古いコメントを非表示
KSSV 2020 年 10 月 28 日
That's what pdist does....did you read the documentation?
M.S. Khan 2020 年 10 月 28 日
Dear KSSV, i am trying to understand its documentation and then will apply. Thanks for your guidance. Regards!

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

### 回答 (1 件)

Jakob 2020 年 10 月 28 日
B = randi([-10 10],5,3); % just some random numbers
minimum = sqrt(sum((B(1,:)- B(2,:)).^2));
for i = 1 : size(B,1)-1
for j = i+1 : size(B,1)
minimum = min(minimum,sqrt(sum((B(i,:)- B(j,:)).^2)));
end
end
disp(minimum)
##### 3 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
M.S. Khan 2020 年 10 月 29 日
Thanks KSSV, pdist() functions works. Thanks for reply Dear Jakob. your code and pdist() function works same.
Jakob 2021 年 3 月 10 日
Hi again, sorry I can't reply in private to your email.
About your question:. "I think pdist2() can only be used for 2D, right.".
Be careful, pdist2() works different then pdist(), you can safely use
min(pdist(YOURMATRIX))
to measure the minimal distance for any dimension. It's basically the same as my code

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

### カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by