让n = 10; 然后,我们如何使用随机节点(替换X和Y值)来生成最短路径,例如以下代码:
x= [1 1 2 2 3 4 6 4 5 5 ];
y= [2 5 3 4 4 5 3 1 2 6 ];
% Random weight for shortestpath
weights = randi(52, size(x));
w = randi([1 10], 13, 1);
D = graph(x,y,weights);
p = plot(D,'x','EdgeLabel',D.Edges.Weight );
path = shortestpath(D,1,5);
highlight(p,path,'NodeColor','g','EdgeColor','g')
谢谢。