You'll need to pay careful attention to what happens with matrix elements that are on the edges of the matrix, as these elements don't have nine neighbors. I often zero-pad to simplify the code.
Also, in that blog post, you'll see this line of code:
neighbors = bsxfun(@plus, idx, neighbor_offsets)
In today's MATLAB, you can write that more simply as:
neighbors = idx + neighbor_offsets
2 Comments
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/705433-neighbor-and-center-points-of-matrix#comment_1235608
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/705433-neighbor-and-center-points-of-matrix#comment_1235608
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/705433-neighbor-and-center-points-of-matrix#comment_1235788
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/705433-neighbor-and-center-points-of-matrix#comment_1235788
Sign in to comment.