How to find local maxima in plot(X,Y)?
Show older comments
Dear Matlab users,
I have two arrays of the same length: X and Y. The function
plot(X,Y)
plots the Y-values against the X-values as I wish. The graph contains remarkable local maxima, but how can I access them? Precisely, I need the Y-value of the local maximum as well as its corresponding X-value.
I am very aware of the function
[peaks,locs] = findpeaks(Y)
but findpeaks only detects peaks in the array Y, not in a "Y against X"-representation. Does anybody have an idea how to detect local maxima in a (X,Y)-plot?
Thank you in advance! Eduard
1 Comment
Azzi Abdelmalek
on 15 Nov 2013
Why [peaks,locs] = findpeaks(Y) doesn't work ?
Accepted Answer
More Answers (2)
Jan
on 15 Nov 2013
0 votes
The definition of "maximum" requires to specify a direction. Usually in X/Y plots this is the Y-direction. Then a peak in the Y-direction is completely independent from the X-values.
My impression is, that you either want something different from a "maximum", e.g. a convex hull, or that findpeaks is sufficient already. Btw. there are many further tools for this job in the FileExchange. Either search there or let an internet search engine do this for you.
Eduard
on 16 Nov 2013
0 votes
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!