필터 지우기
필터 지우기

how to average specific rows of all columns?

조회 수: 11 (최근 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 CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by