Finding an average of sample point in an array with irregular intervals

1 回表示 (過去 30 日間)
Pavel Kutsenko
Pavel Kutsenko 2019 年 1 月 22 日
コメント済み: Pavel Kutsenko 2019 年 1 月 23 日
Hi!
I would like to take an average of sample windows in my data.
(I1 = [1:10])
For regular intervals i could use the
Av1 = mean(I1([1:2:10;2:2:10]))
However, i am currently facing a problem where a gap between windows increases every time by 1 unit. Sort of like that:
Av2=mean(I2([1:(1:4):10;2:(1:4):10]))
How can i do it in Matlab?
  2 件のコメント
Image Analyst
Image Analyst 2019 年 1 月 22 日
Have you tried a nested for loop? Try it.
Pavel Kutsenko
Pavel Kutsenko 2019 年 1 月 22 日
sorry, i have no idea how to implement this

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

回答 (1 件)

Omer Yasin Birey
Omer Yasin Birey 2019 年 1 月 23 日
編集済み: Omer Yasin Birey 2019 年 1 月 23 日
Hi Pavel, you may try this
Av2 = cell(4,4);
% I2 = rand(20,20,20);
for i = 1:4
for j = 1:4
Av2{i,j}=mean([I2(1:i:10),I2(2:j:10)]);
end
end
meanWind = mean(cellfun(@(c) c, Av2(:)));
  3 件のコメント
Omer Yasin Birey
Omer Yasin Birey 2019 年 1 月 23 日
Of course, it is possible. You are changing the columns here so I assumed you want to calculate the mean of columns. You can use the code below for mean of columns. Else if you want to take mean of rows use the second code.
Av2 = zeros(4,4);
% I2 = rand(20,20,20);
for i = 1:4
for j = 1:4
Av2(i,j)=mean([I2(1:i:10),I2(2:j:10)]);
end
end
meanOfEachColumns = mean(Av2',2);
if you want the mean of rows
Av2 = zeros(4,4);
% I2 = rand(20,20,20);
for i = 1:4
for j = 1:4
Av2(i,j)=mean([I2(1:i:10),I2(2:j:10)]);
end
end
meanOfEachColumns = mean(Av2,2);
Pavel Kutsenko
Pavel Kutsenko 2019 年 1 月 23 日
But i dont really have rows or columns, i just have an array of numbers. So if I use this code with I2=[1:10] i get (5.6, 5.3, 5.6, 5.4) as my means and i am looking for (2,3,5,8)

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

カテゴリ

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