Average in a 1D array
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
jinang patel
am 12 Nov. 2019
Beantwortet: Guillaume
am 12 Nov. 2019
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
0 Kommentare
Akzeptierte Antwort
Guillaume
am 12 Nov. 2019
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!