# How to find the input value when outputting the maximum value

4 views (last 30 days)

Commented: 文辉 沈 on 30 Apr 2022
length = max(mi);
The coordinates of the four points A, B, C, and D are known. I have calculated the distance between the two points through pdist2(). I used max() to get the maximum value of these distances. My current requirement is to convert the maximum The two points are connected by a plot() line, so how can I know the coordinates of the two points of the maximum value?

Walter Roberson on 30 Apr 2022
Edited: Walter Roberson on 30 Apr 2022
[max_length, maxidx] = max(mi);
switch maxidx
case 1
coords = {A, B};
case 2
coords = {A, C};
case 3
coords = {A, D};
case 4
coords = {B, C};
case 5
coords = {B, D};
case 6
coords = {C, D};
otherwise
error('strange maximum index!')
end
... It would have been easier to work with the array returned by pdist2() directly.
all_coords = {A, B, C, D};
[max_length, maxidx] = max( reshape(triu(Distance_Matrix), [], 1 );
[R,C] = ind2sub( size(Distance_Matrix), maxidx );
coords = {all_coords{R}, all_coords{C}};
##### 2 CommentsShowHide 1 older comment

I still thank you very much, your help is very useful to me