clc;clear; n=6; %设置矩阵大小 tic; G=zeros(6);%定义n阶零矩阵 G(1,2)=100; G(2,1)=100; G(1,3)=1200; G(3,1)=1200; G(2,3)=900; G(3,2)=900; G(2,4)=300; G(4,2)=300; G(3,4)=400; G(4,3)=400; G(4,5)=1300; G(5,4)=1300; G(4,6)=1400; G(6,4)=1400; G(5,6)=1500; G(6,5)=1500; ind = find(G==0); G(ind)=inf; netCostMatrix = G; for s = 1:4 起点1,2,3,4 for d = 4:6 终点:4,5,6 [shortestPath, totalCost] = dijkstra(netCostMatrix, s, d); print('num2str(s)','num2str(d)'); end end toc; print('num2str(s)','num2str(d)'); 已经定义了迪杰斯特拉函数,调用时候怎么打印从每个起点到每个终点的路径和距离? |