trying to identify the cells within a radius of a certain point (x,y)
1 次查看(过去 30 天)
显示 更早的评论
Hi, I am new to matlab and am trying to identify the cells within a radius of a certain point (x,y) in matrix M. I know of the rangesearch function but don't entirely understand the outputs. Also, is there a way to visualize the "search radius" around a point? like plotting the search radius within the matrix. Thank you in advance
0 个评论
回答(1 个)
KSSV
2016-9-22
clc; clear all ;
N = 100 ;
x = linspace(0,1) ;
y = linspace(0,1,N) ;
[X,Y] = meshgrid(x,y) ;
XX = X(:) ;
YY = Y(:) ;
radius = 0.1 ;
coor = [XX YY] ;
for i = 1:length(coor)
% Get the distance bw ith point and rest all points
data = repmat(coor(i,:),[length(coor),1])-coor ;
dist = sqrt(data(:,1).^2+data(:,2).^2);
% Arrange the distances in ascending order
[val, pos] = sort(dist) ;
% Pick the points which lie within radius
neighbour = pos(val<=radius) ;
plot(XX,YY,'.k')
hold on
plot(XX(i),YY(i),'*b')
plot(XX(neighbour),YY(neighbour),'.r')
hold off
drawnow
end
The above can also be achieved with inbuilt command knnsearch. I hope you are looking for the same.
3 个评论
yubo liu
2016-9-24
This is an example ,N = 100 is only the parameter of the demo ,you should apply the example to you own project ,that's all.hope to help you.
KSSV
2016-9-26
You need not to use meshgrid. Name your (x,y) points as coor (Nx2 vector, where N is number of points). I suggest you to go through the knnsearch document. It is more powerful.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!