I have a code that sums up the 8 by 8 subcell of a 256 by 256 matrix to give a smaller matrix of the size 32 by 32. I use for loops, which make the process slow. Can this be done without using the loop? I need to use this summing code in an optimization tool, CVX, which doesn't go well with in-built MATLAB functions. So, it has to be a code without in-built finctions (sum and mean are allowed though).
img=rand(256);
m=1;
n=1;
for i=1:8:256
for j=1:8:256
temp=img(i:i+7,j:j+7);
D(m,n)=sum(temp(:));
n=n+1;
end
m=m+1;
n=1;
end