MATLAB Answers

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

1 view (last 30 days)
bidlee devi
bidlee devi on 12 Feb 2020
Commented: Matt J on 13 Feb 2020
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 !

  0 Comments

Sign in to comment.

Accepted Answer

Matt J
Matt J on 12 Feb 2020
Edited: Matt J on 12 Feb 2020
out = blockproc(A,[4 4],@(x)mean(x.data(:)));
result = A - repelem( out , 4,4);

  4 Comments

Show 1 older comment
bidlee devi
bidlee devi on 13 Feb 2020
After running the code
result1 = A - repelem( out , 4,4);
It says
"Undefined function 'repelem' for input arguments of type 'double'."

Sign in to comment.

More Answers (1)

Fangjun Jiang
Fangjun Jiang on 12 Feb 2020
Edited: Fangjun Jiang on 12 Feb 2020
A=rand(32);
out = blockproc(A,[4 4],@(x)mean(x.data(:)));
temp=repmat({ones(4,1)},8,1);
temp=blkdiag(temp{:});
Result=A-temp*out*temp'
%% or run below to see the effect
temp*magic(8)*temp'

Sign in to answer this question.

Tags