finding peak value after minimum value

조회 수: 24 (최근 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 CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by