MATLAB: I have a 32 * 32 matrix .i want to take mean of each 4*4 so that the matrix is reduced to 8*8 array. Can anyone help me how to do that

mean

please help me how to take mean of specified dimension from a large array.

Best Answer

Try use blockproc from Image Processing Toolbox
out = blockproc(A,[4 4],@(x)mean(x.data(:)));
variant without Image Processing Toolbox
[m,n] = size(A);
k = [4 4];
[ii, jj] = ndgrid(ceil((1:m)/k(1)),ceil((1:n)/k(2)));
out1 = accumarray([ii(:),jj(:)],A(:),[],@mean);
other variant
[m,n] = size(A);
k = [4 4];
C = mat2cell(A,k(1)*ones(m/k(1),1),k(2)*ones(n/k(2),1));
out = cellfun(@(x)mean(x(:)),C);