I'm new to the MATLAB software and am currently trying to learn it without being formally taught and have a pretty simple question.
I have an adjacency matrix that corresponds to a digraph and want to see what nodes are connected by a walk to other nodes in the network. So, given an adjacency matrix with n nodes:
D = [0,1,1,0,0,0,0;
0,0,0,1,1,0,0;
0,0,0,0,1,0,0;
0,0,0,0,0,1,0;
0,0,0,0,0,1,0;
0,0,0,0,0,0,1;
0,0,0,0,0,0,0]
I want to find the number of unique successors for each node. I am currently using a code to do this, but it is very clunky; every time I change the matrix I need to change the code. It is as follows:
D1 = logical(D^1 + D^2 + D^3 + D^4 + D^5 + D^6 + D^7);
D1(logical(eye(size(D1)))) = 0;
B = sum(transpose(D1));
Is there any way to tidy up the code and just make a more general one!?