Performing a repeated calculation within a vector

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2015-12-7
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by