MATLAB: Maximum position of element in a matrix

matrix

Hi I have a 1000×1000 matrix. I want to find the location and the value of the highest value in the matrix?

Best Answer

Pretty straightforward - the only complicating factor is that max only works down one dimension at a time, so you either have to call it twice or turn the matrix temporarily into a vector. Probably easiest is this:
M = rand(1000);
[maxVal, idx] = max(M(:));
idx is a linear index. If you want the row/column index then
[i, j] = ind2sub(size(M), idx);