How can I add four neighbor elements (left, right, top and bottom) of each element of a given matrix and make a new matrix of the same sixe from the calulated values?
11 views (last 30 days)
Show older comments
For example, let A= [ 0 2 1; 1 0 1; 1 0 2]. Then my resulting matrix should be [3 1 3; 1 4 3; 1 3 1].
0 Comments
Accepted Answer
Image Analyst
on 16 Nov 2015
Use conv2():
A= [ 0 2 1; 1 0 1; 1 0 2]
kernel = [0,1,0;1,0,1;0,1,0]; % Sum above, left, right, and below
B = conv2(A, kernel, 'same')
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!