How to obtain nearest distance between two sets of coordinates

조회 수: 2 (최근 30일)
Shin
Shin 2023년 1월 10일
편집: Matt J 2023년 1월 10일
Hi there, I have two sets of coordinates such as
startpose = [2,1; 4,5; 6,5; 2,3; 8,9];
endpose = [7,6; 2,4; 5,4; 2,9; 1,6;];
how can I obtain the nearest distance between the "startpose" and the "endpose" so that at the end I will have 5 pair of neareast distance between the two sets, and display which are the pair? Thanks
-Chann-

답변 (1개)

Matt J
Matt J 2023년 1월 10일
편집: Matt J 2023년 1월 10일
startpose = [2,1; 4,5; 6,5; 2,3; 8,9];
endpose = [7,6; 2,4; 5,4; 2,9; 1,6;];
[distance, index]=pdist2(startpose,endpose,'euc','Smallest',1);
nearestpoints = startpose(index,:)
nearestpoints = 5×2
6 5 2 3 4 5 4 5 4 5

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by