"Yihui Hung" <a489930026@yahoo.com.tw> wrote in message <gi2ksb$qsa$1@fred.mathworks.com>...
> Hello,
> I have a 6X4 data set and need to average them across every 3X2 data point. The example is as follows:
> 1, 2,3,4;
> 3, 4, 5,6;
> 7, 8, 9,10;
> 11, 12, 13, 14;
> 15, 16,17,18;
> 19,20,21 22;
> I would like to obtain four means from1,3,7,2,4,8;3,5,9,4,6,10;11,15,19,12,16,20;13,17,21,14,18,22. Are there some useful matlab function to do this? Any suggestion will appreciated.
>
> Sincerely,
> Yihui
Let A be your matrix and let the means be taken over p x q submatrices. Then execute the following (mysterious) code:
[M,N] = size(A);
m = M/p; n = N/q; % < m and n must evaluate to integers
[J,I] = meshgrid(p*(0:m*n1)+m*p*(q1)*floor((0:m*n1)/m),...
(1:p*q)+(m1)*p*floor((0:p*q1)/p));
B = reshape(mean(reshape(A(I+J),p*q,m*n)),m,n);
Matrix B will be the requested m x n matrix of mean values.
Roger Stafford
