MATLAB: Compute average of each value in a matrix without using for

filterfor loopMATLABmatrix manipulation

Hi all,
I was wondering is it possible to alter each value of a matrix based on the average value of its neighbors, wihtout using for loops?
Thanks in advance.

Best Answer

you can use conv2 or imfilter, for example
x = magic(3)
y = conv2(ones(3)/9,x)