Hello,
Is there a matlab function that allows to take average in an array over 'n' elements:
A=[10 20 30 40]
output=[15 35]
Kind Regards,
Jinang

 채택된 답변

Guillaume
Guillaume 2019년 11월 12일

1 개 추천

Assumming the number of elements of the vectors is a multiple of n, reshape the vector in columns of n rows and take the mean across the rows:
assert(mod(numel(A), n) == 0, 'number of elements of A is not a multiple of n');
result = mean(reshape(A, n, []), 1)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2019년 11월 12일

답변:

2019년 11월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by