Average of the Vector elements in the matrix

I have a matrix of 815*440 and I need to take the average of every 20 elements in all the rows and find the output as 815*22
Any help is appreciated
Thanks

댓글 수: 3

Kirby Fears
Kirby Fears 2015년 9월 16일
편집: Kirby Fears 2015년 9월 16일
Trying to understand your questions: are you trying to compute the mean of columns 1, 21, 41,..., 421 for each row, then repeat this exercise for columns 2, 22, ... , 422, and keep repeating until you have a 815 x 22 matrix of such means? This would actually give an 815 x 20 matrix...
Are you instead trying to take the average of columns 1,2,...,20 for each row, and repeat for columns 21,22,...,40, etc until you get to the mean of columns 421,422,...,440? This would give an 815 x 22 output as you mentioned.
Jab
Jab 2015년 9월 16일
I am trying to do your second option
Kirby Fears
Kirby Fears 2015년 9월 16일
편집: Kirby Fears 2015년 9월 16일
The answer I posted below solves that problem. Please give it a try.

댓글을 달려면 로그인하십시오.

 채택된 답변

Kirby Fears
Kirby Fears 2015년 9월 16일
편집: Kirby Fears 2015년 9월 16일

0 개 추천

Below is a loop to take the mean of the first 20 columns, then the next 20 columns, etc. Let me know if this is not the computation you were trying to perform.
% Creating dummy matrix for example solution
a=reshape(1:815*440,815,440);
% Width of column groupings
colgroup=20;
% Initialize mean results array
results=NaN(size(a,1),size(a,2)/colgroup);
% Take means in loop
for iter=1:size(results,2),
startcol=colgroup*(iter-1)+1;
results(:,iter)=mean(a(:,startcol:startcol+colgroup-1),2);
end,

추가 답변 (1개)

James Tursa
James Tursa 2015년 9월 16일
편집: James Tursa 2015년 9월 16일

0 개 추천

Assuming you are averaging every 20 elements, not a sliding window:
A = your 815 x 440 matrix
m = mean(reshape(A',20,[]));
Anew = reshape(m,22,[])';

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

Jab
2015년 9월 16일

편집:

2015년 9월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by