trying to identify the cells within a radius of a certain point (x,y)
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
KSSV
le 22 Sep 2016
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 commentaires
yubo liu
le 24 Sep 2016
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
le 26 Sep 2016
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.
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!