I would like to create all possible adjacency matrices (zero diagonal) of an undirected node graph n
.
For example, without re-marking for n=3
we get 2 3 (3-1) / 2 = 8 possible network configurations (or adjacency matrices).
One solution that works for n = 3
(and which I find pretty dumb) is the following:
n = 3;
A = [];
for k = 0:1
for j = 0:1
for i = 0:1
m = [0 , i , j ; i , 0 , k ; j , k , 0 ];
A = [A, m];
end
end
end
In addition, I believe that this happens faster, but something is wrong with my indexing, since there are 2 matrices missing:
n = 3
C = [];
E = [];
A = zeros(n);
for i = 1:n
for j = i+1:n
A(i,j) = 1;
A(j,i) = 1;
C = [C,A];
end
end
B = ones(n);
B = B- diag(diag(ones(n)));
for i = 1:n
for j = i+1:n
B(i,j) = 0;
B(j,i) = 0;
E = [E,B];
end
end
D = [C,E]
Is there a faster way to do this?
source
share