How to find the input value when outputting the maximum value
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
文辉 沈
am 30 Apr. 2022
Kommentiert: 文辉 沈
am 30 Apr. 2022
[mi] = [dab,dac,dad,dbc,dbd,dcd];
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?
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 30 Apr. 2022
Bearbeitet: Walter Roberson
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Predictive Maintenance Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!