# Findpeak from the graph in specific range

35 ビュー (過去 30 日間)
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.
%% 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 2021 年 5 月 26 日

[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 件のコメント表示 1 件の古いコメント非表示 1 件の古いコメント
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 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