title: MATLAB Average Every 5 Elements
body: <p>I want to take a large matrix and take the average of all 5x5 grids in it. </p>
  
  <p>The matrix is 245x85x1255.I  reshaped the matrix into a 5x4165x1255 size (the z dimension is not that important) and I want to take the average of elements 1:5, 5:10, 10:15 etc in each row. And then, with the resulting matrix, I want to average the five columns. Then I'll resize it back to it's original shape (but smaller of course). </p>
  
  <p>I don't have to do it this way. I just need to take a 5x5 grid and average all the points in it. Then I take the next 5x5 grid next to it and average all those points.</p>
  
  <p>Here's how I did it for the first 5x5 grid:</p>
  
  <pre><code>A = data_SpecificArea(:,1:5,:);
  B = mean(A,2);
  C = mean(B,1);
  </code></pre>
  
  <p>** Here's the working code using blockproc</p>
  
  <pre><code>% Change dataAll_SpecificArea to a 1x1 degree grid (5x5 block averaging)
  fun = @(block_struct) mean(block_struct.data);
  A = blockproc(dataAll_SpecificArea,[5 1],fun); % Size goes from 245x85x1255 to 49x85x1255
  B = blockproc(A,[1 5],fun); % Size is 49x17x1255
  </code></pre>