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!