Average of the Vector elements in the matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
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
2015년 9월 16일
편집: Kirby Fears
2015년 9월 16일
The answer I posted below solves that problem. Please give it a try.
채택된 답변
Kirby Fears
2015년 9월 16일
편집: Kirby Fears
2015년 9월 16일
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,
댓글 수: 0
추가 답변 (1개)
James Tursa
2015년 9월 16일
편집: James Tursa
2015년 9월 16일
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,[])';
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!