0

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?

2 Answers 2

3

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)]);
Sign up to request clarification or add additional context in comments.

Comments

1

Another possible solution:

ZNames = {'A','B','C','D','E'}
biggestVar = ZNames(find(Z==max(Z),1,'first'))

Result

biggestVar = 'E'

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.