From: Matt J on
"Young Ryu" <ryuyr77(a)gmail.com> wrote in message <hlq4rf$9vl$1(a)fred.mathworks.com>...
> Hi
>
> I have an array:
> A=rand(1000, 1000);
> I'd like to resize to 25% size (thus 250 by 250) using average. I usd resizem funciton, but it was quite slow. Could you recommend the fastest way to resize array?
====================

As long as A is not sparse, the following is the fastest way I know

B=downsamp2d(A,[4,4]);


function M=downsamp2d(M,bindims)
%DOWNSAMP2D - simple tool for 2D downsampling
%
% M=downsamp2d(M,bindims)
%
%in:
%
% M: a matrix
% bindims: a vector [p,q] specifying pxq downsampling
%
%out:
%
% M: the downsized matrix

p=bindims(1); q=bindims(2);
[m,n]=size(M); %M is the original matrix

M=sum( reshape(M,p,[]) ,1 );
M=reshape(M,m/p,[]).'; %Note transpose

M=sum( reshape(M,q,[]) ,1);
M=reshape(M,n/q,[]).'; %Note transpose

M=M/(p*q);