matlab已知30个点经纬度要求距离小于n的点连线,并求距离,求算法.x=[108.95304108.948646108.943245108.94338108.953261108.944739108.952711108.950219108.94584108.936101108.966846108.958679108.954148108.953211108.954652108.955135108.94
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/17 01:49:40
matlab已知30个点经纬度要求距离小于n的点连线,并求距离,求算法.x=[108.95304108.948646108.943245108.94338108.953261108.944739108.952711108.950219108.94584108.936101108.966846108.958679108.954148108.953211108.954652108.955135108.94
matlab已知30个点经纬度要求距离小于n的点连线,并求距离,求算法.
x=[108.95304
108.948646
108.943245
108.94338
108.953261
108.944739
108.952711
108.950219
108.94584
108.936101
108.966846
108.958679
108.954148
108.953211
108.954652
108.955135
108.943435
108.96003
108.952525
108.953716
108.954037
108.940287
108.944593
108.933135
108.962475
108.959052
108.956224
108.945436
108.953232
108.950231
];
y=[34.324856
34.323761
34.326451
34.333263
34.334844
34.33871
34.351631
34.347578
34.35333
34.362683
34.321815
34.320295
34.320764
34.319554
34.325214
34.32663
34.327857
34.333069
34.333088
34.3361
34.339862
34.339132
34.342854
34.346602
34.347604
34.347537
34.347805
34.362334
34.330315
34.353367
];
plot(x,y,'*');
for i=1:30 %为点的个数
text(x(i),y(i),sprintf('%d',i)) %x,y为坐标值
end
matlab已知30个点经纬度要求距离小于n的点连线,并求距离,求算法.x=[108.95304108.948646108.943245108.94338108.953261108.944739108.952711108.950219108.94584108.936101108.966846108.958679108.954148108.953211108.954652108.955135108.94
你这是求任意两点间距离,或叫欧氏距离求法.分一下几步:
1)形成距离求解矩阵N*2维
C=[x y]
2)、求任意点距离
for i=1:30
for j=1:30
D(i,j)=sqrt((C(i,1)-C(j,1))^2+(C(i,2)-C(j,2))^2);
end
end
3)因为每个点到自身的距离为0,故将每个点到自身的距离设为无限大:
for i=1:30
D(i,i)=inf;
end
4)求距离小于n的距离点标号
[Fx Fy]=find(D<n);
Fx和Fy存储的为距离小于n点标号,比如Fx(1)=4,Fy(1)=5,则45两点间距离小于n.
5)画连线
Fn=length(Fx);%满足要求的点对个数
%连起来
for i=1:Fn;
pI=Fx(i); %起点标号
pJ=Fy(i); %终点标号
line([x(pI,1) x(pJ,1)],[y(pI,1) y(pJ,1)])
D(Fx(i),Fy(i));
% xmid=(x(pI,1)+x(pJ,1))/2;
% ymid=(y(pI,1)+y(pJ,1))/2;
% str=num2str(D(Fx(i),Fy(i)));
% text(xmid,ymid,str)
end