Findpeak from the graph in specific range

조회 수: 25 (최근 30일)
Harsimranjot Grewal
Harsimranjot Grewal 2021년 5월 26일
댓글: Allen 2021년 5월 27일
Hello Everyone,
I am trying to use the findpeaks function in my code but in a specific range.In the code below you can see I have a plot of x2 and y2.From this plot, I want to find the peak at x2 values between 90 and 120.BUt my code doesnt work for the peaks and shows a blank graph.Any help would be appreciated.
Data = xlsread('test.xlsx');
%% Step 2 data
x2 =Data(655:8466,6); % Sample temprature
y2 =Data(655:8466,3); % Umsubstracted temprature
figure
plot(x2,y2);
set(gca,'ydir', 'reverse')
title('Step 2 Data')
hold on
[pks, locs]= findpeaks((x2(90:120)),'Npeaks',1)
title('Peak for step 2')

답변 (1개)

Allen
Allen 2021년 5월 26일
편집: Allen 2021년 5월 27일
[pks, locs]= findpeaks((x2(90:120)),'Npeaks',1)
In your above line of code, you are indexing x2 from elements 90 through 120 and not from between the values of 90 and 120. To find the indices of x2 with values in your preferred range use the following instead.
% Between 90 and 120, but not equal to 90 or 120.
idx = x2>90 & x2<120;
% If you want to include values equal to 90 and 120, then use
idx = x2>=90 & x2<=120;
Using the correct index, use the following with findpeaks.
[pks, locs] = findpeaks((x2(idx)),'Npeaks',1);
  댓글 수: 2
Harsimranjot Grewal
Harsimranjot Grewal 2021년 5월 27일
Thanks for your answer but it didnt work and the command line says ' Array indices must be positive integers or logical values." I just replaced the code with your answer.So, any other recommendations.
Allen
Allen 2021년 5월 27일
@Harsimranjot Grewal looks like repeated the applying the index to x2 more than once. I have made corrections to my example.
Changed idx = x2(x2>90 & x2<120); to idx = x2>90 & x2<120; and idx = x2(x2>=90 & x2<=120); to idx = x2>=90 & x2<=120; which work better.

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

카테고리

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