finding peak value after minimum value

19 ビュー (過去 30 日間)
Jan Kasparek
Jan Kasparek 2022 年 2 月 7 日
コメント済み: Mathieu NOE 2022 年 3 月 14 日
Hi,
I have data of Sound Pressure Level and I need to find first maximum (not global) after global minimum. I dont know if its clear, so I will show it at an example at picture attached. There is a global minimum (22.09) and I need to find value of peak right after (57.969). I cant use "min" command since the value of peak is not global maximum. Hope its clear now. Is there some way how I can do this?
Thanks in advance,
J.

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 2 月 7 日
hello
this would be my suggestion - I added also the local peak "before" the global min also for sake of convenience
clc
clearvars
% dummmy data
n = 50;
x = 1:n;
y = 5*rand(1,n) + 55;
y(22) = 10;
% find global min
[y_min,ind_min] = min(y);
x_min = x(ind_min);
% find all peaks
ind_peaks = find(islocalmax(y));
x_peaks = x(ind_peaks);
y_peaks = y(ind_peaks);
% find local maximum before and after global min
% local maximum before global min
tmp1 = find(x_peaks <= x_min,1,'last');
ind_before = ind_peaks(tmp1);
% local maximum after global min
tmp2 = find(x_peaks >= x_min,1,'first');
ind_after= ind_peaks(tmp2);
figure(1)
plot(x,y,x_min,y_min,'dk',x(ind_before),y(ind_before),'dg',x(ind_after),y(ind_after),'dr');
legend('data','global min','local max before','local max after');
ylim([0 1.25*max(y)]);
  2 件のコメント
Jan Kasparek
Jan Kasparek 2022 年 3 月 14 日
sorry for late answer but.. thanks a lot, it helped
Mathieu NOE
Mathieu NOE 2022 年 3 月 14 日
hello
my pleasure !

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by