MATLAB Answers

Outputing a correspond element of another variable

16 views (last 30 days)
Cutie
Cutie on 30 Dec 2020
Commented: Ameer Hamza on 30 Dec 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).

Accepted Answer

Ameer Hamza
Ameer Hamza on 30 Dec 2020
Edited: Ameer Hamza on 30 Dec 2020
Try this
A = ["Bayo" "Tun" "s"];
B = [21, 45, 11];
[~, idx] = max(B);
output = A(idx);
Result
>> output
output =
"Tun"
  4 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!