find the furthest point

18 visualizaciones (últimos 30 días)
Hassan
Hassan el 26 de Sept. de 2013
Comentada: Image Analyst el 27 de Sept. de 2013
if i have an two arrays like that:
x=[ 39 63 71 7 53 39 64 23 29 65 ];
y=[ 20 11 22 78 61 71 9 20 78 94 ];
and
AA=[x ; y];
if p1 = (39,20) and p2 =(63,11)
how can i find the furthest point in AA than the points p1 and p2
Thanks, Hrabei
  3 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 27 de Sept. de 2013
Editada: Azzi Abdelmalek el 27 de Sept. de 2013
Hassan, If you have two point p1 and p2, and two other points p3 and p4, how will you choose p3 rather than p4. What is your mathematics criterion?
Image Analyst
Image Analyst el 27 de Sept. de 2013
The phrase "how can i find the furthest point in AA than the points p1 and p2" does not make grammatical sense. Do you really mean "how can i find the furthest point in AA from the points p1 and p2"??? In other words, find the point in AA farthest from point p1, and then also find the furthest point in AA from point p2? And why are p1 and p2 already inside AA ? Do they need to be, or is that just a coincidence? Please clarify.

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 26 de Sept. de 2013
Editada: Image Analyst el 27 de Sept. de 2013
Try this:
x=[ 39 63 71 7 53 39 64 23 29 65 ];
y=[ 20 11 22 78 61 71 9 20 78 94 ];
AA=[x ; y]
% Find point in AA closest to p1.
p1 = [39,20]
squaredDistance = sum((AA-repmat(p1', [1, size(AA, 2)])).^2, 1)
[maxSqDist1, indexOfMax1] = max(squaredDistance)
% Find point in AA closest to p2.
p2 =[63,11]
squaredDistance = sum((AA-repmat(p2', [1, size(AA, 2)])).^2, 1)
[maxSqDist2, indexOfMax2] = max(squaredDistance)
In the command window, you'll see:
AA =
39 63 71 7 53 39 64 23 29 65
20 11 22 78 61 71 9 20 78 94
p1 =
39 20
squaredDistance =
0 657 1028 4388 1877 2601 746 256 3464 6152
maxSqDist1 =
6152
indexOfMax1 =
10
p2 =
63 11
squaredDistance =
657 0 185 7625 2600 4176 5 1681 5645 6893
maxSqDist2 =
7625
indexOfMax2 =
4
  4 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 27 de Sept. de 2013
What I've understood from his question is to find the two points (Pn,Pm) with distance Pn-Pm closest to the distance P1-P2. The points are not necessary the closest. The function fullfact (statitistic toolbox) can be replaced by ndgrid function
Image Analyst
Image Analyst el 27 de Sept. de 2013
I didn't think of that, but it could be. It's not really clear and specifically stated.

Iniciar sesión para comentar.


Azzi Abdelmalek
Azzi Abdelmalek el 26 de Sept. de 2013
Editada: Azzi Abdelmalek el 27 de Sept. de 2013
AA=[x ;y];
id=numel(x);
idx=unique(sort(fullfact([id id]),2),'rows');
idx(~diff(idx'),:)=[]
distance=sqrt((x(idx(:,1))-x(idx(:,2))).^2+(y(idx(:,1))-y(idx(:,2))).^2);
%----------------------------------------------------------------------
%p1 = (39,20) and p2 =(63,11)
x1=39;
y1=20;
x2=63;
y2=11;
dist1= sqrt((x1-x2)^2+(y1-y2)^2);
%----------------------------------------------------------------------
a=abs(distance-dist1);
[ii,jj]=sort(a);
id=jj(2);
point1=AA(:,idx(id,1))
point2=AA(:,idx(id,2))
%or
AA=[x ;y];
id=numel(x);
[ii,jj]=ndgrid(1:id,1:id);
idx=[jj(:) ii(:)]
idx=unique(sort(idx,2),'rows');
idx(~diff(idx'),:)=[]
distance=sqrt((x(idx(:,1))-x(idx(:,2))).^2+(y(idx(:,1))-y(idx(:,2))).^2);
%----------------------------------------------------------------------
%p1 = (39,20) and p2 =(63,11)
x1=39;
y1=20;
x2=63;
y2=11;
dist1= sqrt((x1-x2)^2+(y1-y2)^2);
%----------------------------------------------------------------------
a=abs(distance-dist1);
[ii,jj]=sort(a);
id=jj(2);
point1=AA(:,idx(id,1))
point2=AA(:,idx(id,2))

Categorías

Más información sobre Signal Processing Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by