Q&A
Ask and answer questions to make information more available to wider audiences.
Cooper Keystone @cooperkeystone   18, Aug 2023 12:00 AM
find the indices of the maximum (or minimum) value of a matrix
How to find the indices of the maximum (or minimum) value of a matrix?
answers 1
 
Answer 1
Cesar Borne @bornecesar   30, Aug 2023 05:33 PM
The min and max functions in MATLAB return the index of the minimum and maximum values, respectively, as an optional second output argument.
For example, the following code produces a row vector 'M' that contains the maximum value of each column of 'A', which is 3 for the first column and 4 for the second column. Additionally, 'I' is a row vector containing the row positions of 3 and 4, which are 2 and 2, since the maximums for both columns lie in the second row.
>> A = [1 2; 3 4]
A =
   1   2
   3   4
>> [M,I] = max(A)

M =

   3   4

I =

   2   2