Findpeak from the graph in specific range
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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')
0 comentarios
Respuestas (1)
Allen
el 26 de Mayo de 2021
Editada: Allen
el 27 de Mayo de 2021
[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 comentarios
Allen
el 27 de Mayo de 2021
@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.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!