Counting Neighboring Cells

4 次查看(过去 30 天)
freel
freel 2011-2-27
Hi, I've been recently having trouble in creating a functions that would count the number of neighboring 1's in an array. So say for example I had an array that consisted of
1 0 1 1 0 1 1 0
1 1 0 1 0 1 1 0
I would want it to return
2 4 3 2 4 3 3 2
2 3 4 2 4 3 3 2
How would I go about this?
Much appreciated

采纳的回答

Bruno Luong
Bruno Luong 2011-2-27
A=[1 0 1 1 0 1 1 0;
1 1 0 1 0 1 1 0]
B = ones(3);
B(2,2) = 0;
conv2(A,B,'same')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by