how to average specific rows of all columns?

2 ビュー (過去 30 日間)
laxminarayana pasupuleti
laxminarayana pasupuleti 2017 年 6 月 10 日
回答済み: J Yadav 2019 年 1 月 16 日
i am having 100x32 matrix in my data set. i would like to average 20 rows of all columns, like first 20rows average, next 20 and so..on...
can any one help in this problem.
  2 件のコメント
the cyclist
the cyclist 2017 年 6 月 10 日
Would the output be, in your example, a 5x32 matrix?
laxminarayana pasupuleti
laxminarayana pasupuleti 2017 年 6 月 12 日
yes

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

採用された回答

the cyclist
the cyclist 2017 年 6 月 10 日
編集済み: the cyclist 2017 年 6 月 10 日
If I understand your question correctly, you can use the movmean command:
% Some made-up data
A = rand(100,32);
N = 20;
movingAverageA = movmean(A,[(N-1) 0]); % Trailing average of N rows
output = movingAverageA(N:N:end,:);
  3 件のコメント
Image Analyst
Image Analyst 2017 年 6 月 12 日
Did you get it working? You've accepted this answer so I assume so.
laxminarayana pasupuleti
laxminarayana pasupuleti 2017 年 6 月 12 日
in my version its not woking..so i am trying latest version...

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

その他の回答 (2 件)

J Yadav
J Yadav 2019 年 1 月 16 日
to take a moving average of 1 to 20 rows, then 21-40 rows, then 41-60 rows etc.
of a data matrix with n rows and m columns.
you may also try:
for i=1:(n/20) % given that n is a multpile of 20 or your choice of no. of rows to average.
a=(i-1)*20+1;
b=(i-1)*20+20;
meandata(i,:) = mean(data(a:b,:),1);
end

Image Analyst
Image Analyst 2017 年 6 月 10 日
編集済み: Image Analyst 2017 年 6 月 12 日
The first index are the rows. For example to average only the first 20 rows
columnMeans = mean(data([1:20], :), 1);
Or to average rows 34, 23, and 194, do
rowsToAverage = [34, 23, 194];
columnMeans = mean(data(rowsToAverage, :), 1);
  2 件のコメント
laxminarayana pasupuleti
laxminarayana pasupuleti 2017 年 6 月 12 日
this is not working
Image Analyst
Image Analyst 2017 年 6 月 12 日
This seems to work:
data = randi(9, 100, 32) % Sample 100x32 data
columnMeans = [
mean(data([1:20], :), 1);
mean(data([21:40], :), 1);
mean(data([41:60], :), 1);
mean(data([61:80], :), 1);
mean(data([81:100], :), 1)]
Is that what you want?

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

カテゴリ

Help Center および File ExchangeGeometry and Mesh についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by