function[d,index1,index2]=Dijkf(a)

M=max(max(a));

pb(1:length(a))=0;

pb(1)=1;

index1=1;

index2=ones(1:length(a));

d(1:length(a))=M;

d(1)=0;

temp=1;

while sum(pb)<length(a)

tb=find(pb==0);

d(tb)=min(d(tb),d(temp)+a(temp,tb));

tmpb=find(d(tb)==min(d(tb)));

temp=tb(tmpb(1));

pb(temp)=1;

index1=[index1,temp];

index=index1(find(d(index1)==d(temp)-a(temp,index1)));

if length(index)>=2

index=index(1);

end

index2(temp)=index;

end

clear

M=100000;

a(1,:)=[0,7,M,6,10,10,13,8,M];

a(2,:)=[zeros(1,2),2,M,M,M,M,M,6];

a(3,:)=[zeros(1,3),M,5,M,M,M,4];

a(4,:)=[zeros(1,4),M,M,M,4,M];

a(5,:)=[zeros(1,5),M,9,M,4];

a(6,:)=[zeros(1,6),7,6,M];

a(7,:)=[zeros(1,7),M,M];

a(8,:)=[zeros(1,8),M];

a(9,:)=zeros(1,9);

a=a+a';

[d index1 index2]=Dijkf(a);

d

报错内容:您的代码中有一个错误,即在调用函数Dijkf时,没有传递参数a。请修改代码,在调用Dijkf函数时传递参数a。


原文地址: http://www.cveoy.top/t/topic/pCpT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录