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.

11 ビュー (過去 30 日間)
Phung Khai
Phung Khai 2021 年 10 月 23 日
回答済み: Chunru 2021 年 10 月 23 日
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

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by