Paul
Posts:
2
Registered:
4/3/09


Re: second largest element in a matrix
Posted:
Apr 3, 2009 7:00 PM


"Oluwa KuIse" <wespeakforex@yahoo.com> wrote in message <gav3p9$som$1@fred.mathworks.com>... > Hello, > Can anyone pls tell me how I can find the second (or third) largest element in a matrix AND its position. The max function gives the largest element and its position but how do I find the second largest element and its position?
if temp is your vector, you can get the second largest element as follows:
[c,i] = max(temp(temp~=max(temp))) why would you sort it? this is the whole point of logical addressing in matlab.

