MATLAB: Finding a 2d block with highest average inside a 2d window

matrixmatrix manipulation

Consider a matrix A(52,34) How to find out which 2d block size(3,3) has the highest average in it

Best Answer

[~, idx] = max(conv2(A, ones(3,3),'same'))
[r, c] = ind2sub(size(A), idx);
r and c is now the index of the center of the block that had the highest average.