How to find n values before and after a maximum of an array

1 回表示 (過去 30 日間)
Coryn Melissa LLamoza Carabali
Coryn Melissa LLamoza Carabali 2020 年 10 月 15 日
コメント済み: Ameer Hamza 2020 年 10 月 16 日
Hi, everybody, new to Matlab. I want to be able to locate the maximun peak which is known(always at 1) and to be able to extract the data right before and after this maximun peak(see example on figure). And this should be done even if the max-peak value changes along the x-as. Please help :(
  2 件のコメント
Mathieu NOE
Mathieu NOE 2020 年 10 月 15 日
hello
use the "findpeaks" function to localise the peak signal position (index)
from this index value you can easily define a lower index = peak_index - 10 and an upper index = peak_index + 10
and generate an extract of your signal : signal_extract = signal(lower index : upper index)
good luck
Coryn Melissa LLamoza Carabali
Coryn Melissa LLamoza Carabali 2020 年 10 月 16 日
Hi, thank you for your answer. Is 'signal' a function? it doesn't seem to work :(

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

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 15 日
編集済み: Ameer Hamza 2020 年 10 月 15 日
Something like this will work
x; % array of x-values
y; % array of y-values
[max_y, max_idx] = max(y);
x_max = x(max_idx);
interval = 0.02; % length of interval before and after peak
idx = (x_max-interval < x) & (x < x_max+interval);
x_interval = x(idx);
y_interval = y(idx);
x_interval and y_interval contain values in around the peak.
  2 件のコメント
Coryn Melissa LLamoza Carabali
Coryn Melissa LLamoza Carabali 2020 年 10 月 16 日
You are a Genius! it works. thank you so much
Ameer Hamza
Ameer Hamza 2020 年 10 月 16 日
I am glad to be of help! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by