MATLAB: Max

matrix manipulationmax

Hi,
I'm selecting the max of three different values
distmax=max([dist1 dist2 dist3])
which gives for example
distmax= 3.434
is there a possibility to have the name of the value instead of the value itself, like
distmax = dist1
thank you

Best Answer

No.
You can, however, use
[distmax, idx] = max([dist1 dist2 dist3])
and then idx will indicate which index in to the [dist1 dist2 dist3] matrix was the maximum. To figure out which of the variables that came from, you would need to know the size()'s of the variables.
It would be easier if you used
[distmax, idx] = max([max(dist1(:)), max(dist2(:)), max(dist3(:))])
and then idx would indicate which variable number the max was found in; relating the variable number to the variable name is a different matter.
Plain
[distmax, idx] = max([dist1 dist2 dist3])
is the abbreviation for the above for the special case where dist1, dist2, and dist3 are all guaranteed to be scalars (something your question does not allow us to assume).
Question: what do you want to happen if the identical maximum value exists in more than one of the variables?