Azzera filtri
Azzera filtri

trying to identify the cells within a radius of a certain point (x,y)

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

KSSV
KSSV il 22 Set 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 Commenti
yubo liu
yubo liu il 24 Set 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
KSSV il 26 Set 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.

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by