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

조회 수: 5(최근 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표시숨기기 이전 댓글 수: 4
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표시숨기기 이전 댓글 수: 2
Jakob 2021년 3월 10일
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

댓글을 달려면 로그인하십시오.

### 범주

Find more on Hierarchical Clustering in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by