I would like to be able to find the position of the two greatest local maxima in a list.
For the example: list={1,2,3,4,2,1,2,6,5,4,3,2,}
I would like to return {4,8}
Initially I was using the Ordering[list,-2]
to successfully do this, however, the above scenario shows that this fails quite easily (here 5>4).
I then tried using Ordering[MaxDetect[list],-2]
which almost does the job; however, I have the problem that my list is long and has many (smaller) local maxima, which MaxDetect
makes equal in value to the 2 larger local maxima, so Ordering
fails to select the appropriate peaks.
Is there a way of retaining the relative sizes of the peaks after using MaxDetect
, so that this method will work?
Thanks!
**Using the option MaxDetect[list,value]
does not work, as different runs change the value that these maxima have.
{pos, value} = Transpose@FindPeaks[list]
.pos
will return position desired {4,8} $\endgroup$