How to get the largest element index in matlab array

MonsterMMORPG picture MonsterMMORPG · Nov 28, 2012 · Viewed 14.3k times · Source

Here is a simple double array:

array=[3 1 1]

Largest element index is 1

or:

array=[3 9 1]

Largest element index is 2

How can I get the largest element index?

Answer

Tim picture Tim · Nov 28, 2012

Use the second output argument of the max function:

[ max_value, max_index ] = max( [ 3 9 1 ] )