请教matlab distance编程问题!i=1;r=111;x=[113.9406587 113.9041632 113.968498 113.910984 113.9005583];y=[22.5181577 22.5142117 22.533583 22.545299 22.481226];a=[113.917584 113.9284293 113.9552785 113.96736 113.925868 113.924434 113.9365961 113.92

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/05 01:21:31

请教matlab distance编程问题!i=1;r=111;x=[113.9406587 113.9041632 113.968498 113.910984 113.9005583];y=[22.5181577 22.5142117 22.533583 22.545299 22.481226];a=[113.917584 113.9284293 113.9552785 113.96736 113.925868 113.924434 113.9365961 113.92
请教matlab distance编程问题!
i=1;
r=111;
x=[113.9406587 113.9041632 113.968498 113.910984 113.9005583];
y=[22.5181577 22.5142117 22.533583 22.545299 22.481226];
a=[113.917584 113.9284293 113.9552785 113.96736 113.925868 113.924434 113.9365961 113.9209741 113.9089594 113.913741 113.9652023 113.9079182 113.9210733 113.935431 113.945898 113.957863 113.927181 113.917737 113.9296796 113.930893 113.997946 113.9542274 113.9561252 113.9685093 113.9769529 113.91288 113.95153 113.939578 113.930444 114.010386 113.9968406 113.9552785 113.989949];
b=[22.543844 22.5462122 22.5726856 22.58409 22.616353 22.566134 22.5567698 22.5356669 22.5132914 22.515488 22.5647133 22.5140571 22.5324251 22.533423 22.588272 22.558265 22.538267 22.519218 22.4836936 22.487975 22.594341 22.5684955 22.5405532 22.546613 22.5627809 22.513839 22.63656 22.621165 22.532987 22.595791 22.5371481 22.5726856 22.587905];
for k=1:5
for n=1:33
a=distance([b(n),a(n)],[y(k),x(k)])
d=111*a
%c=r*(acos(cos(b(n))*cos(y(k))*cos(a(n)-x(k))+sin(b(n))*sin(y(k))))
i=i+1
end
end
运行后出现这样的错误,知道经纬度,我想用for循环来求任意两点间的距离,请问要怎么修改!建模要用到,急,
Attempted to access a(2); index out of bounds because numel(a)=1.
Error in ==> moni_2 at 10
a=distance([b(n),a(n)],[y(k),x(k)])

请教matlab distance编程问题!i=1;r=111;x=[113.9406587 113.9041632 113.968498 113.910984 113.9005583];y=[22.5181577 22.5142117 22.533583 22.545299 22.481226];a=[113.917584 113.9284293 113.9552785 113.96736 113.925868 113.924434 113.9365961 113.92
以前搞建模在网上下到的代码,不是自己编的,但经过试验可以用,分享了:
function len=dijkstra(Input)
%最短路Dijkstra算法,同时给出路径,input为图矩阵
row=size(Input,1);
%赋初值
% s_path=1;
distance=inf*ones(1,row);
distance(1)=0;
% flag(1)=1;
temp=1;
%求起点到各点的最短路的权
% s_path=ones(1,3);
while length(s_path)<row
pos=find(Input(temp,:=inf);
n=length(pos);
flag=ones(1,n);
for i=1:n
if (isempty(find(s_path==pos(i),1)))&&(distance(pos(i))>...
(distance(temp)+Input(temp,pos(i))))
distance(pos(i))=distance(temp)+Input(temp,pos(i));
flag(pos(i))=temp;
end
end
k=inf;
for i=1:row
if (isempty(find(s_path==i,1)))&&(k>distance(i))
k=distance(i);
temp_2=i;
end
end
s_path=[s_path,temp_2];
temp=temp_2;
end
%用追溯法得到起点到各点的最短路的路线
len=zeros(1,row);
for endpoint=1:row
path=0; %初始化
path(1)=endpoint;
i=1;
while path(i)~=1
path(i+1)=flag(path(i));
i=i+1;
end
path(i)=1;
path=path(end:-1:1); %最短路径
short_distance=distance(endpoint); %最短路径权
len(endpoint)=short_distance; %起点到各点的最短距离
pathall=path; %总路径矩阵
end
len=len(25:end);
%{
disp('起点到各点的最短路径:');
celldisp(pathall);
%设法只画出最短路径
em=find(w==inf);
w(em)=0;
h = view(biograph(w,[],'ShowWeights','on'));
%}
邮箱给你发了个资料,多年前搞的,估计是忘了,也许这个函数有点问题,你按资料里的做吧