Neighbor searching
이전 댓글 표시
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 ?
채택된 답변
추가 답변 (1개)
Sean de Wolski
2011년 12월 28일
Or:
sz = 10;
I = false(sz);
I(4,5) = true; %point we care about
[row col] = find(imdilate(I,true(3)))
카테고리
도움말 센터 및 File Exchange에서 Nearest Neighbors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!