MATLAB: Averaging Data in Buckets of Size n

MATLAB

I have 250000 data points and I would like to filter that such that every 10 data points is averaged to one data point. How can I do this?

Best Answer

You can reshape the matrix such that it has 'n' rows. Once this is done, you can take the mean of the reshaped matrix and this will give the mean of every 'n' elements. Try the following:
myData = 1:200;
n = 10;
% Reshape the matrix such that it has 'n' rows
reshapedData = reshape(myData, n, [ ]);
% Take the average of each column
averageMatrix = mean(reshapedData);