Finding minima

I have a data file with few valleys (minima). is there a way to find all the x coordinates corresponding to each minimum y value?

 Accepted Answer

Matt Tearle
Matt Tearle on 15 Feb 2011
If you want fancy, take Walter's advice and search FEx. If you want quick and dirty:
x = 1:50;
y = sin(5*x);
idx = [false, y(3:end)>y(2:end-1) & y(2:end-1)<y(1:end-2), false];
xmin = x(idx)
plot(x,y,'o-',xmin,y(idx),'rx')

7 Comments

Walter Roberson
Walter Roberson on 15 Feb 2011
The above code unfortunately picks up on every local valley; the contributions in the FEX worry about noise and defining how much of a change there can be before saying that one has entered a new extreme or if two adjacent extreme should be considered part of the same series or not...
Matt Tearle
Matt Tearle on 15 Feb 2011
Right, that's why I said "quick and dirty"
Paulo Silva
Paulo Silva on 15 Feb 2011
Matlabs findpeaks will do the job just fine, the recent matlab version have a better implementation of findpeaks.
Matt Tearle
Matt Tearle on 15 Feb 2011
True, but note: FINDPEAKS is a Signal Processing Toolbox function.
Paulo Silva
Paulo Silva on 15 Feb 2011
Matt your simple detection is very interesting :) I never thought about it that way, it's not perfect but might be very useful, thanks for sharing it.
Matt Tearle
Matt Tearle on 16 Feb 2011
Hah. Actually I just hunt the intartubes looking for places to apply logical indexing! ;)
Paulo Silva
Paulo Silva on 16 Feb 2011
Here's my 1 vote :)

Sign in to comment.

More Answers (3)

Walter Roberson
Walter Roberson on 15 Feb 2011

0 votes

There is are a fair number of postings, and several Matlab File Exchange contributions, for finding peaks, which you could either modify or apply to the negative of your data.
Graig
Graig on 15 Feb 2011

0 votes

Thanks All. For me actually the 'quick and dirty' way works well, as the data are very smooth (not noisy). Seemed to me, this is what the black box 'findpeaks' contains in a better way.

1 Comment

Matt Tearle
Matt Tearle on 16 Feb 2011
To help others who might have the same question, it would be great if you could vote for and/or accept answers that you think should be given prominence. Thanks.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!