How to find local maxima in plot(X,Y)?

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

 Accepted Answer

More Answers (2)

Jan
Jan on 15 Nov 2013
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
Eduard on 16 Nov 2013
First of all, thank you Jan Simon and meihua for your answers! At the end, peakdet did the job for me.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 15 Nov 2013

Answered:

on 16 Nov 2013

Community Treasure Hunt

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

Start Hunting!