How to average a specific number elements which have the same index value

Hi there,
I am trying to create a function which finds the average of a number of elements in columns that have a similar index value in another column, in my attempt below I can find the average of say last two elements when they are ordered sequentially however am not sure how to find the average of say prior two elements only when the index values match.
function avgprevious2elements(a)
[nrows, ncolumns] = size(a);
new = zeros(nrows,ncolumns);
for i=3:nrows
for j=3:ncolumns
new(i,j)= (a(i-1,j) + a(i-2,j))/2
end
end
Any assistance you are able to offer is greatly appreciated.

답변 (0개)

카테고리

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

질문:

2016년 1월 22일

편집:

2016년 1월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by