Neighbor searching
Show older comments
Hello!
I have a meshgrid created like this:
x=1:10; y=1:10; [X Y]=meshgrid(x,y);
X =
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
and
Y =
1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6 6
7 7 7 7 7 7 7 7 7 7
8 8 8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9 9
10 10 10 10 10 10 10 10 10 10
I would like to implement a neighbor searching as follow: - select one position (X=4,Y=5) - obtain as output the coordinates of the points close to the previous one; in the case of a matrix (for example) 1X1 this would be: 1) X=3 Y=4 2) X=4 Y=4 3) X=5 Y=4 4) X=3 Y=5 5) X=5 Y=5 6) X=3 Y=6 7) X=4 Y=6 8) X=5 Y=6
Is there any function that does that in matlab ?
Accepted Answer
More Answers (1)
Sean de Wolski
on 28 Dec 2011
Or:
sz = 10;
I = false(sz);
I(4,5) = true; %point we care about
[row col] = find(imdilate(I,true(3)))
Categories
Find more on Nearest Neighbors in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!