MATLAB: Calculate the mean of several columns

matrixmean

Hi all, I am new to Matlab and I am struggling with this problem. I have a matrix with 112 columns and 100 rows. How can I calculate the mean of column 1-7 , 8-14, 15-21,…., 106-112 and put the a new matrix with 16 columns and 100 rows. I appreciate your help Sobhan

Best Answer

One way is simply with a for loop
A = randn(100,112);
for nn = 0:15
B(:,nn+1) = mean(A(:,nn*7+1:(nn+1)*7),2);
end