flow 4d double matrix fourth dimension 2 . want implement loop without using loops. essentially , each index in third dimension,, want divide flow1 square blocks of size block-size , calculate mean of values in fourth dimension of each block, assign values respective fourth dimension elements in block . typical values [height width n block_size] = [ 480 640 100 8] . guaranteed block_size factor of both height , width [height,width,n,~] = size(flow1); reduced_flow = zeros(size(flow1)); ii = 1:block_size:height jj = 1:block_size:width k = 1:n reduced_flow(ii:ii+block_size-1,jj:jj+block_size-1,k,1) = mean(mean(flow1(ii:ii+block_size-1,jj:jj+block_size-1,k,1),1),2); reduced_flow(ii:ii+block_size-1,jj:jj+block_size-1,k,2) = mean(mean(flow1(ii:ii+block_size-1,jj:jj+block_size-1,k,2),1),2); end end end example flow1 = round(10*rand(4,4,2,2)); block_size = 2; [flow1 reduced_flow] ans(:,:,1,1) = 6.0000 4.0000 ...