How to average a specific number elements which have the same index value
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!