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

6 ビュー (過去 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 Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by