matlab里的矩阵不明白,求解释

2019-07-17 13:44发布

a=[
0 8 5 9 12 14 12 16 17 22 Inf Inf
8 0 9 15 17 8 11 18 14 22 8 8
5 9 0 7 9 11 7 12 12 17 5 5
9 15 7 0 3 17 10 7 15 18 9 9
12 17 9 3 0 8 10 6 15 15 12 12
14 8 11 17 8 0 9 14 8 16 14 14
12 11 7 10 10 9 0 8 6 11 12 12
16 18 12 7 6 14 8 0 11 11 16 16
17 14 12 15 15 8 6 11 0 10 17 17
22 22 17 18 15 16 11 11 10 0 22 22
Inf 8 5 9 12 14 12 16 17 22 0 Inf
Inf 8 5 9 12 14 12 16 17 22 Inf 0
]
a=a+a';
c1=[1 10 6 4 12 5 2 7 11 8 9 3 1];(这一句是什么意思??)
L=length(c1);
flag=1;
while flag>0
flag=0;
for m=1:L-3
for n=m+2:L-1
if a(c1(m),c1(n))+a(c1(m+1),c1(n+1))<a(c1(m),c1(m+1))+a(c1(n),c1(n+1))
flag=1;
c1(m+1:n)=c1(n:-1:m+1);
end
end
end
end
sum1=0;
for i=1:L-1
sum1=sum1+a(c1(i),c1(i+1));
end
circle=c1;
sum=sum1;
c1=[ 1 2 12 3 11 4 5 8 10 9 6 7 1];%改变初始圈,该算法的最后一个顶点不动
flag=1;
while flag>0
flag=0;
for m=1:L-3
for n=m+2:L-1
if a(c1(m),c1(n))+a(c1(m+1),c1(n+1))<...
a(c1(m),c1(m+1))+a(c1(n),c1(n+1))
flag=1;
c1(m+1:n)=c1(n:-1:m+1);
end
end
end
end
sum1=0;
for i=1:L-1
sum1=sum1+a(c1(i),c1(i+1));
end
if sum1<sum
sum=sum1;
circle=c1;
end
circle,sum

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。