Azzera filtri
Azzera filtri

Performing a repeated calculation within a vector

1 visualizzazione (ultimi 30 giorni)
Hi Everyone, I have a column of data, say with 40,000 data points. I want to reduce this to 4,000 by creating a new variable which is the mean of every 10 data points. So the new variable would have the mean of the first 10 data points, followed by the mean of the second 10 data points, and so on until there are 4,000 data points.Thanks.

Risposta accettata

Walter Roberson
Walter Roberson il 7 Dic 2015
Provided that the vector length is an exact multiple of the group size,
mean( reshape(TheVector, GroupSize, []) )
If there would be an incomplete group then you need to either pad the vector or else handle it differently. If you have a fairly new MATLAB then you can pad with NaN and use the 'omitnan' flag to mean(); see http://www.mathworks.com/help/matlab/ref/mean.html

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by