필터 지우기
필터 지우기

creating two pairs of data which are apart by a certain distance

조회 수: 3 (최근 30일)
Any idea as to how to create two sets of coordinates whose eucleadian distance from every other coordinate is greater than a certain threshold.
In other words i want to get coordinates which dont have any neighbours within a certain radius
Any suggestions?

채택된 답변

Stefan
Stefan 2012년 5월 8일
use epsilon-nearest neighbors algorithm.
or simple: if your data have the coordinates x and y and TH = tour predefied threshold then calculate:
for i=1:length(x)
d=sqrt((x-x(i)).^2 +(y-y(i)).^2);
if d<=TH
datax(i)=x(i);
datay(i)=y(i);
else
outlyerx(i)=x(i);
outlzery(i)=y(i);
end
end
datax(datax==0)=[];
datay(datay==0)=[];
outlyerx(outlyerx==0)=[];
outlyery(outlyery==0)=[];
  댓글 수: 2
Stefan
Stefan 2012년 5월 8일
this code will seperate one data set in 2 other with either at least one neighbor or none neighbor is in it's radius==TH
if you want to create 2 data sets than jan simons solution is the best way!
Bharathwaj
Bharathwaj 2012년 5월 9일
Sorry for not posting in depth details about the requirement. Apologies..
The problem is i ve two arrays say x and y containing the coordinates to a surface. I dont want any two coordinates to llie within a certain distance..or say a radius...
If i use the above suggestion, i am not able to achieve it..for whatever be the value of "TH" its not sorting it...
I would be actually doing this i guess:
First calculate the distances of the current coordinate point with others..and check the distance array and if its below the "TH" delete the corresponding coordinate value from the original value.
Is this logical ?
Thanks for your input guys :)

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Stefan
Stefan 2012년 5월 8일
if the data set i very large you have to vectorize the code...

Jan
Jan 2012년 5월 8일
Please post more details. Currently this is the most simply solution:
% First set of points:
range = 100;
X = rand(100, 3) * range;
% Second set, all point must have distance > 5
distance = 5;
Y = X + (range + distance);

카테고리

Help CenterFile Exchange에서 3-D Scene Control에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by