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 vue (au cours des 30 derniers jours)
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.

Réponses (1)

Chunru
Chunru le 23 Oct 2021
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

Tags

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by