Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I have an array Z:
A=2; B=3; C=4; D=5; E=6; Z=[A B C D E];
I want to find the max value of Array Z and also get the 'name of the variable' that has that max value. How to do this?
You can do this:
A=2; B=3; C=4; D=5; E=6; Z=[A B C D E]; x = ['A' 'B' 'C' 'D' 'E']; [maximum,idx] = max(Z); disp(['maximum is :' num2str(maximum)]); disp(['variable name is :' x(idx)]);
Add a comment
Another possible solution:
ZNames = {'A','B','C','D','E'} biggestVar = ZNames(find(Z==max(Z),1,'first'))
Result
biggestVar = 'E'
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.