I want to average each element of an m by n matrix with surrounding w elements, for example, if w = 1, the element would be the mean of the 3×3 submatrix with the element in the middle, i.e, if the matrix is
a = [1:10;2:11;3:12;4:13;5:14;6:15;7:16]
and w = 1, each element would be average of nearby eight elements and itself.
I tried using 3 loops, i = 1:w, 1 = w+1:end-w, i = end-w+1:end, but there must be a quicker way to do this.
Best Answer