For rows and 2 columns, containing xOy coordinates of the point. Look for the two points with the furthest distance and return the row index of those two points.

조회 수: 2 (최근 30일)
Please, Can y help me :
For rows and 2 columns, containing xOy coordinates of the point. Look for the two points with the furthest distance and return the row index of those two points.

답변 (1개)

Chunru
Chunru 2021년 10월 23일
n = 8;
xy = rand(n, 2);
d = pdist(xy);
D = squareform(d)
D = 8×8
0 0.7326 0.0969 0.6177 0.0679 0.3563 0.4383 0.6051 0.7326 0 0.8275 0.1851 0.7570 0.9674 0.3597 0.2801 0.0969 0.8275 0 0.7146 0.1120 0.2977 0.5343 0.7009 0.6177 0.1851 0.7146 0 0.6287 0.9018 0.1958 0.0989 0.0679 0.7570 0.1120 0.6287 0 0.4032 0.4407 0.6054 0.3563 0.9674 0.2977 0.9018 0.4032 0 0.7528 0.9152 0.4383 0.3597 0.5343 0.1958 0.4407 0.7528 0 0.1668 0.6051 0.2801 0.7009 0.0989 0.6054 0.9152 0.1668 0
[~, idx]= max(D(:));
[i, j] = ind2sub([n n], idx)
i = 6
j = 2

카테고리

Help CenterFile Exchange에서 Simulation, Tuning, and Visualization에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by