MATLAB: 3-D matrix operations

3dfor loopmatrix

I have a 5X126 matrix that I am splitting into a [5,21,6] matrix using reshape. I want to average the values of neighboring columns in each of these submatrices and store them into a final 3-d matrix that will be [5 20 6]. How can i write a for loop to do this?
I am very new to Matlab so any help would be appreciated. Thanks!

Best Answer

Assuming that for the average of columns you want the result that Turlough specified, then
RefBloAvg = movmean(RefBlock,[0 1],2);
RefBloAvg(:,end,:) = [];
Note that this does not need to be in a loop of any kind. It works on the entire array at once.