Link: http://nw360.blogspot.com/2006/12/matlab-find-maximum-in-matrix.html
Suppose we have a matrix a,
a =
81 91 27 96 95
90 63 54 15 48
12 9 95 97 80
and now we want to locate the maximum value 97. There are several approaches.
Use max only.
>> [row_val row_ind] =max(a, [], 1)
row_val =
90 91 95 97 95
row_ind =
2 1 3 3 1
>> [col_val col_ind] =max(row_val)
col_val =
97
col_ind =
4
The maximum value is at [row_ind(col_ind), col_ind]
Use find.
>> [r c] =find(a==max(a(:)))
r =
3
c =
4
Use single index.
>> [s_v s_i] =max(a(:))
s_v =
97
s_i =
12
>> [r c] =ind2sub(size(a), s_i)
r =
3
c =
4
*******************************************
Usually, to find the maximum value of a matirx, the following command is used:
max(a(:)) where a is a 2D matrix
The problem is that if the matrix size is too big, you may get yourself involved in a problem that is ??? Matrix is too large to convert to linear index. This is caused by a(:).
Try to use max(max(a)) instead.