MATLAB: Using reshape to get a block averaging of data when it is not divisible by the block

meanreshape

Have varying data sets of varying lengths i want to block average (every 10 points), block max/min, stdev, etc. How can I use reshape to do so and avoid the not divisible error? for example my data set is 1086 rows and i want every 10, the last set can be an average of 6 points only which is fine.

Best Answer

If you have the Image Processing Toolbox, you could use blockproc for this.
% data
x = rand(1086,104);
% Mean
blockproc(x,[10 10],@(s)mean(s.data(:)))
% Min
blockproc(x,[10 10],@(s)min(s.data(:)))
etc.