Reputation: 87
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?
Upvotes: 0
Views: 91
Reputation: 5822
Another possible solution:
ZNames = {'A','B','C','D','E'}
biggestVar = ZNames(find(Z==max(Z),1,'first'))
Result
biggestVar = 'E'
Upvotes: 1
Reputation: 313
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)]);
Upvotes: 3