find the furthest point
20 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Azzi Abdelmalek
2013 年 9 月 27 日
編集済み: Azzi Abdelmalek
2013 年 9 月 27 日
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
2013 年 9 月 27 日
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.
回答 (2 件)
Image Analyst
2013 年 9 月 26 日
編集済み: Image Analyst
2013 年 9 月 27 日
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 件のコメント
Azzi Abdelmalek
2013 年 9 月 27 日
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
2013 年 9 月 27 日
I didn't think of that, but it could be. It's not really clear and specifically stated.
Azzi Abdelmalek
2013 年 9 月 26 日
編集済み: Azzi Abdelmalek
2013 年 9 月 27 日
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))
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Signal Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!