# Compute average of each value in a matrix without using for

2 views (last 30 days)

Show older comments

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.

##### 2 Comments

the cyclist
on 31 Oct 2012

### Accepted Answer

Honglei Chen
on 31 Oct 2012

you can use conv2 or imfilter, for example

x = magic(3)

y = conv2(ones(3)/9,x)

##### 5 Comments

### More Answers (0)

### See Also

### Categories

### Products

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!