Effacer les filtres
Effacer les filtres

Performing a repeated calculation within a vector

1 vue (au cours des 30 derniers jours)
Dirk
Dirk le 7 Déc 2015
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.

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Déc 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

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by