First, create a graph.
M = eye(100) + triu(rand(100) < 0.035);
You will agree this matrix satisfies the requirements, in the sense that node 1 can possibly talk to only nodes below node 1, and down the line. If it bothers you that the matrix representing the connections is purely upper triangular, I could randomize the matrix, but that does nothing except rename the nodes. Node 1 could have any name or number you want to assign to it.
G = digraph(M)
G =
digraph with properties:
Edges: [272x2 table]
Nodes: [100x0 table]
Now, the question was asked, if everything can communicate in this graph. Here, clearly, just a plot of the graph shows that will fail, because some nodes are obviously disconnected from the rest.
I think conncomp could possibly help here, but for it to do what I want, I need to have a symmetric graph matrix.
unique(CC)
ans =
1 2 3
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
And this tells me there were multiple distinct groups which did not talk to each other. I suppose I could have done this too:
SP1 = shortestpathtree(G,1)
SP1 =
digraph with properties:
Edges: [7x2 table]
Nodes: [100x0 table]
So at the top of the tree is node 1. And we see that some nodes can be reached from node 1, but there were many nodes which were unreachable, shown off to the side on the top row.