Help in finding values between limits

조회 수: 2 (최근 30일)
Duncan
Duncan 2014년 8월 27일
답변: Chad Greene 2014년 8월 27일
The brackets on the left are the coordinates of various points along the left black line. the red lines connecting the two black lines indicate the distance (in pixels).
I have the matrix A:
A = 3 0
2 2
2 1
3 3
which corresponds to the coordinate points I am looking for satisfying the equation of a line ( (x - a)^2 + (y - b)^2 = r^2 ).
Now, x & y correspond to the values in matrix A, while a & b correspond to the coordinate points (in brackets on the image) r is the pixel distance
An example using the point (0,2):
a = 0, b = 2, r = 2
if I implement this code:
B = A((A(:,1)-a).^2+(A(:,2)-b).^2==r^2,:);
I will get a matrix displaying the following:
B = 2 2
Now what I want to do is make sure that only 1 value is displayed in B using the condition that
a - r < x < a + r
&
b - r < y < b + r
where x and y are the values in B, I want this to be done to make sure that I am displaying only one the closest point which satisfies.

답변 (1개)

Chad Greene
Chad Greene 2014년 8월 27일
John D'Errico's ipdm function is very good at finding nearest neighbors.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by