I have a nx2 matrix of to-from nodes for a large network structure. I have used this to create a sparse adjacency matrix which I can plot using BIOGRAPH. My systems varies in size, the largest ones having more than 3000 nodes (obviously not suitable for plotting).
If I choose a line, I want to be able to create a list of all lines and nodes that are within X "steps" from the original line (two nodes), for a given X (typically 3). It's clearly not too difficult using brute-force. However, I need to do this as quick as possible.
adj_mat = sparse(from_nodes, to_nodes, 1, s, s);
Is there a way I can to this using the adjacency matrix? Can I do it more efficiently using the to/from list?
What I do now is finding the indices for the nodes connected to the chosen line, then search through the entire list of to-from nodes and finding all lines where either the to/from element is equal to one of the nodes of the chosen line. Then I use the new list of nodes and search through the entire to/from list, searching for these nodes again.
The code I use now looks something like this:
k = 1;
for i = 1:nnz(nodeList)
for j = 1:n
if branchList(j,1) == nodeList(i) || branchList(j,2) == nodeList(i)
tempBranch(k) = j;
k = k + 1;
end
end
end
Thank you!