To find the 2nd MINIMUM and/or the MAXIMUM value(s) from a Matlab Plot

조회 수: 7 (최근 30일)
Frank Lehmann
Frank Lehmann 2018년 2월 15일
댓글: Star Strider 2018년 2월 15일
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

답변 (1개)

Star Strider
Star Strider 2018년 2월 15일
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
Frank Lehmann
Frank Lehmann 2018년 2월 15일
Thanks Star Strider,
However, Im still a little unclear on how peaks and minprominence actually works and which is the preferred function islocalmax/min or peaks? Remember I am after the 2nd value only for both maxima and minima.
Cheers!
Star Strider
Star Strider 2018년 2월 15일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by