MATLAB: A is a matrix of size 32*32.I want to subtract elements of each 4*4 block of A from their respective 4*4 means

subtract

A is a matrix of size 32*32. out = blockproc(A,[4 4],@(x)mean(x.data(:)));
Using the above code, I am able to reduce A to 8*8 which is obtained by averaging each 4*4 blocks of A. Now, I want to subtract elements of each 4*4 block of A from their respective 4*4 means. Thanks !

Best Answer

out = blockproc(A,[4 4],@(x)mean(x.data(:)));
result = A - repelem( out , 4,4);