求两点间的距离
axis([0 100 0 100]);xlabel('Width of the Area(m)')
ylabel('Length of the Area(m)')
grid
hold on
C=[0 0 0 0 0 0 0 0 0 0 0;10 10 10 10 10 10 10 10 10 10 10;20 20 20 20 20 20 20 20 20 20 20;30 30 30 30 30 30 30 30 30 30 30;40 40 40 40 40 40 40 40 40 40 40;50 50 50 50 50 50 50 50 50 50 50;60 60 60 60 60 60 60 60 60 60 60;70 70 70 70 70 70 70 70 70 70 70;80 80 80 80 80 80 80 80 80 80 80;90 90 90 90 90 90 90 90 90 90 90;100 100 100 100 100 100 100 100 100 100 100]
D=C'
for n=1:60;
x(n)=rand()*100;y(n)=rand()*100;A=(x);B=(y);
E=C-A(n);
F=D-B(n);
H=E.^2+F.^2;
Q=sqrt(H);
i(n)=sum(C(find(Q<=8.94)))/length(C(find(Q<=8.94)));
j(n)=sum(D(find(Q<=8.94)))/length(D(find(Q<=8.94)));
M=(i);N=(j);
plot(i,j,'pk');
plot(x,y,'.b');
end
上面这段代码中,我想求distance=sqrt((M(i)-A(x))^2+(N(j)-B(y))^2),可是怎么怎么写都出错,请问是哪里的问题??能不能把正确的代码帮忙写出来~谢谢~~
[[it] 本帖最后由 yobey 于 2008-9-11 16:57 编辑 [/it]]