Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Index for max element in a matrix?
Replies: 8   Last Post: May 16, 2012 1:38 PM

 Messages: [ Previous | Next ]
 Loren Shure Posts: 1,349 Registered: 12/7/04
Re: Index for max element in a matrix?
Posted: Jun 11, 2008 9:23 AM

In article <484f04fb\$0\$90270\$14726298@news.sunsite.dk>, asd@asd.com
says...
> I have this matrix:
>
> A = [15 12 11;
> 20 44 23;
> 33 32 34];
>
>
> Is there a function in matlab that returns the x and y index for the
> maximum/minimum element? In this case the function should return (2,2).
>
> If I use:
>
> find(A==(max(max(A))))
>
> I just get 5.
>
>
>

[maxA,ind] = max(A(:));
[m,n] = ind2sub(size(A),ind)

--
Loren
http://blogs.mathworks.com/loren/

Date Subject Author
6/10/08 AnasiZ
6/10/08 dpb
6/11/08 Jos
5/16/12 Jan
5/16/12 Matt J
5/16/12 Matt J
6/10/08 us
6/10/08 us
6/11/08 Loren Shure