MATLAB: Matrix size is A(100*100). Weighted average of the 4 elements.

MATLAB and Simulink Student Suitemeanweighted average

How to store the result in a matrix which contains the average the 4 elements in the cluster A11, A12,A21,A22 and similarly A13,A14.A23,A24 and goes on? The resultant matrix should be 25*25

Best Answer

In the original question and the image you mentiones 2x2 submatrices. In the commend you talk of 4x4 submatrices. This is not clear in this sentence also:
These 4x4 matrices are unique; i.e., I have to take the first two elements of the first row and same elements of the second row and average it.
Here I used n=4, but perhaps you want n=2:
n = 4;
X = rand(100, 100);
Y = reshape(X, [n, 100/n, n, 100/n]);
Y = permute(Y, [2, 4, 1, 3]); % Move dims of length n together
Y = reshape(Y, [100/n, 100/n, n*n]); % Combine to subvectors of length n*n
Result = mean(Y, 3); % Mean over 3rd dimension