I would like to be able to find the position of the two greatest local maxima in a list.
For the example:
I would like to return
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?
**Using the option
MaxDetect[list,value] does not work, as different runs change the value that these maxima have.