To find the 2nd MINIMUM and/or the MAXIMUM value(s) from a Matlab Plot
6 views (last 30 days)
Show older comments
I have this problem I wish to find the 2nd highest minima or 2nd least maxima of a plot? Unfortunately the Minimum y-value falls to 0 on the x-axis and the maximum value rises to 200 (as an example) on the y-axis, so I want to find the next least Maximum value on the y - axis for Maximum and the next greater Mininum value on the y-axis from the Mininum, and construct a vertical line to each of these points? I've tried the index functions (min, max etc) but as expected I get 0, 200. From there I wish to add an annotation with the num2str, text, Vertical/HorizontalAlignment commands etc which I have NO problem with. I could get the values manually of course from the plot, but this means I would need to repeat it time after time if any of the parameters change. I could also perform a manual calculation within the script and then call it up as a text value and then plot but rather it was done automatically. Any ideas anyone?
Regards, Frank
0 Comments
Answers (1)
Star Strider
on 15 Feb 2018
If you have R2017b, the islocalmax (link) and islocalmin functions will let you detect and define the extrema. If you have the Signal Processing Toolbox, use the findpeaks (link) function on your signal to find the peaks, and on the negative of your signal to find the minima.
2 Comments
Star Strider
on 15 Feb 2018
My pleasure.
I generally use 'MinPeakHeight' and 'MinPeakDistance' to characterise the peaks I want findpeaks to return. They’re usualy enough. I have no idea what your data are or how noisy they are, so I recommend that you experiment with the function with your data to find out what works.
After using findpeaks to get the peaks, you will have to write the code to identify and store the correct peaks and valleys.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!