MATLAB Simple MATLAB- how to find indices of max element in matrix?

AI Thread Summary
To find the indices of the maximum value in a 10x10 matrix using MATLAB, the max() function can be utilized effectively. While max() typically returns the maximum value, it can also return the index of that value when used correctly. The common approach involves using the syntax [value, index] = max(matrix(:)), which flattens the matrix into a vector and retrieves the maximum value along with its linear index. To convert this linear index back to row and column indices, the ind2sub function can be employed. This method provides a straightforward solution for obtaining the position of the maximum value within the matrix.
mikeph
Messages
1,229
Reaction score
18
Hi,

Say I have a 10x10 matrix, is there a simple code to finding the indices of the maximum value?

I'm trying to use max() but there doesn't appear to be any option of actually returning the index, rather than the value. I don't need the value, just the position.

Thanks,
Mike
 
Physics news on Phys.org
This thread on MATLAB Central should give you a decent answer: http://www.mathworks.com/matlabcentral/newsreader/view_thread/170759
 

Similar threads

Replies
1
Views
4K
Replies
3
Views
3K
Replies
5
Views
1K
Replies
3
Views
7K
Replies
4
Views
2K
Replies
8
Views
2K
Back
Top