Asked by Asyran Abdullah
on 12 Oct 2018 at 23:40

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.

Opportunities for recent engineering grads.

Apply Today
## 6 Comments

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423747-make-all-point-connected-to-other-points#comment_621691

What should 1 and 2 connect to? You do not have them in your node list, x, and you have not added an edge for them.

## Asyran Abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423747-make-all-point-connected-to-other-points#comment_621694

This is just an example, how to add 1&2 in edges without change x value?

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423747-make-all-point-connected-to-other-points#comment_621699

What should they be connected

toand with what weight?In the test I just ran, 1, 2, and 8 all showed up isolated. I guess 8 happened to get mapped to 8 by chance, and then when you removed the edges from nodes to themselves, it ended up isolated.

## Asyran Abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423747-make-all-point-connected-to-other-points#comment_622077

Yes, what i mean is just to make all points connected to each other.

As shown in figure, how can we make all points has an edges to connect to others?

Without changing the x value?

I try to use "UseGravity" and it not function.

## Asyran Abdullah (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423747-make-all-point-connected-to-other-points#comment_622082

For example,

we add num 2 in x.

How to add automatically the missing numbers (2,5,6,7,10,11,12,13,14) into x ?

## Walter Roberson (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/423747-make-all-point-connected-to-other-points#comment_622087

You mean like

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.

Sign in to comment.