MATLAB: Adding matrices inside a big matrix

adding matrices

Hello everybody,
I am wandering if there is a way for not using loops to add many small matrices inside a big matrix. For example I have a big 40000×240000 matrix and I want to add all the numbers of 4×4 matrices inside that matrix, resulting in a 10000×60000 matrix.
thank you all for your answers

Best Answer

And this fun answer:
sum4x4 = reshape(sum(reshape(reshape(sum(reshape(B,4,[])),size(B,1)/4,[])',4,[])),size(B)./4);
sum4x4 = reshape(sum4x4,size(sum4x4,2),size(sum4x4,1))'
where B is your matrix.