필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Stephanie Diaz
Stephanie Diaz 2016년 9월 21일
댓글: KSSV 2016년 9월 26일
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

답변 (1개)

KSSV
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
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
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by