Outputing a correspond element of another variable

1 vue (au cours des 30 derniers jours)
Cutie
Cutie le 30 Déc 2020
Commenté : Ameer Hamza le 30 Déc 2020
I want my final output to be the element A that is equivalent to B(max)
A = ["Bayo" "Tun" "s"]
B = [21, 45, 11]
example
max(B) = 45
How do I output the corresponding element in A (in it original string format).

Réponse acceptée

Ameer Hamza
Ameer Hamza le 30 Déc 2020
Modifié(e) : Ameer Hamza le 30 Déc 2020
Try this
A = ["Bayo" "Tun" "s"];
B = [21, 45, 11];
[~, idx] = max(B);
output = A(idx);
Result
>> output
output =
"Tun"
  4 commentaires
Cutie
Cutie le 30 Déc 2020
Thank you so much!
Ameer Hamza
Ameer Hamza le 30 Déc 2020
I am glad to be of help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by