Averaging specified number of points around the minimum value

1 回表示 (過去 30 日間)
Meghan
Meghan 2024 年 12 月 3 日
コメント済み: Meghan 2024 年 12 月 3 日
Hi,
I'm trying to average a specified number of points around the minimum value of my data (ex. 5 points to the left and 5 points to the right) and cannot seem to find a solution. I'm just not sure how to create that range.
I'm assuming it would be something along the lines of mean(min( %my range)).
Thanks in advance for any help!
  2 件のコメント
Torsten
Torsten 2024 年 12 月 3 日
So you have an array "data", the minimum is at data(ix) for some index "ix" and you want to compute the average of [data(ix-5:ix-1),data(ix+1:ix+5)] ?
Meghan
Meghan 2024 年 12 月 3 日
Yes, thank you! Why include the ix+/-1?

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

採用された回答

Torsten
Torsten 2024 年 12 月 3 日
移動済み: Torsten 2024 年 12 月 3 日
data(ix-5:ix-1) are the 5 points left to the minimum, data(ix+1:ix+5) are the five points right to the minimum.
So the code should be
[~,ix] = min(data);
max_left = min(5,ix-1);
max_right = min(5,numel(data)-ix);
avg = mean([data(ix-max_left:ix-1),data(ix+1:ix+max_right)])
  1 件のコメント
Meghan
Meghan 2024 年 12 月 3 日
I see, thank you very much for your help!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by