amc
amc

Reputation: 833

Return variable name associated with maximum value Matlab

I would like to return the maximum value between two, but return the variable that is assigned to that number...not the number itself.

A = 3

B = 7

max(A,B)

    7

Instead, I would like to return

'B'

I am sorry if this is an obvious question. I just have not found an answer online.

Upvotes: 0

Views: 118

Answers (1)

mhopeng
mhopeng

Reputation: 1081

if B >= A
  Bigvar='B';
else
  Bigvar='A';
end

But I should say that in general if you need to know a variable name the way you describe then there are probably better ways of structuring your code. That's why it doesn't come up when you search.

Upvotes: 1

Related Questions