Make all point connected to other points.

1 回表示 (過去 30 日間)
Asyran Abdullah
Asyran Abdullah 2018 年 10 月 12 日
コメント済み: Walter Roberson 2018 年 10 月 14 日
Hi, i want to make all point has a connection to other with the following code.
x = [6 3 5 4 7 8];
idx = randperm(length(x));
y = x(idx);
start = x(:,2);
last = x(:,(length(x)));
w=randi(100, size(x));
G = digraph(x,y,w);
G = rmedge(G, 1:numnodes(G), 1:numnodes(G));
plot(G,'EdgeLabel',G.Edges.Weight) ;
path = shortestpath(G, start, last);
disp(['spf = ' num2str(path)]);
The result:
Is that possible to all point include no1 & 2 connect to each other?
Thanks.
  6 件のコメント
Asyran Abdullah
Asyran Abdullah 2018 年 10 月 14 日
For example,
x = [1 3 4 8 9 15];
we add num 2 in x.
x1 = [x, 2];
How to add automatically the missing numbers (2,5,6,7,10,11,12,13,14) into x ?
Walter Roberson
Walter Roberson 2018 年 10 月 14 日
You mean like
x = min(x) : max(x)
Or should it be assumed that 1 will always be included?
If some of the values have been excluded, how do we know that the maximum has been included?
If it were a matter of figuring out which vertices did not have any edges incident to them, then that would not be difficult... though it does still assume that the maximum is present.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by