# How to draw a network of nodes in circular formation with links between nodes in MATLAB?

3 views (last 30 days)
Haya Ali on 25 May 2023
Commented: Steven Lord on 25 May 2023
I have a connectivity matrix
and I want a figure like this for my matrix.
A= [-1 -1 0 0 0 0 0 1 0 1 0 0 -1 1 1 -1 1 0 -1 1 -1 1 0;
1 -1 0 0 -1 0 -1 -1 0 0 -1 1 0 0 0 -1 1 -1 0 -1 -1 0 1;
0 1 -1 0 0 0 -1 1 -1 -1 -1 1 0 0 0 0 -1 0 0 -1 1 0 0;
1 0 0 1 0 0 -1 -1 0 0 0 1 -1 0 0 -1 1 -1 0 -1 -1 1 1;
-1 0 -1 0 1 0 0 1 0 1 0 -1 -1 1 1 0 0 0 0 1 1 0 0;
0 0 -1 0 0 0 1 0 0 1 0 0 1 -1 0 1 0 -1 1 1 -1 1 -1;
1 0 0 0 -1 0 0 1 0 1 -1 -1 -1 0 0 -1 -1 -1 0 0 -1 1 0;
1 0 1 0 1 0 0 1 0 0 1 1 -1 1 0 -1 0 0 0 0 -1 -1 0;
0 0 -1 -1 0 0 0 -1 0 -1 0 1 1 0 1 -1 1 -1 -1 -1 -1 0 0;
0 -1 -1 -1 1 0 0 -1 0 0 0 0 1 1 0 -1 1 0 0 -1 -1 0 1;
0 0 1 0 -1 0 -1 0 0 1 -1 -1 0 0 -1 0 -1 0 -1 1 1 1 1;
-1 0 0 1 1 0 -1 -1 0 -1 -1 1 -1 0 -1 0 0 1 0 1 1 0 1;
0 -1 -1 0 1 0 -1 -1 0 -1 0 0 -1 0 0 -1 1 0 0 1 0 0 -1;
0 -1 0 -1 -1 0 0 -1 0 0 0 -1 1 1 0 0 1 0 0 -1 -1 0 0;
-1 0 -1 -1 1 0 0 1 0 1 0 -1 1 1 1 -1 0 0 -1 0 0 -1 -1;
-1 0 0 1 0 -1 -1 -1 0 -1 -1 1 -1 0 0 0 0 0 -1 1 1 1 1;
0 -1 -1 0 1 0 -1 -1 0 -1 0 0 1 0 0 1 0 0 0 1 1 1 -1;
1 1 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-1 0 -1 -1 1 0 0 1 0 1 0 -1 1 1 1 -1 0 0 -1 0 0 -1 -1;
-1 0 0 1 0 -1 -1 -1 0 -1 -1 1 -1 0 0 0 0 0 -1 1 1 1 1;
0 -1 -1 0 1 0 -1 -1 0 -1 0 0 1 0 0 1 0 0 0 1 1 1 -1;
1 1 -1 0 -1 0 -1 1 0 1 -1 -1 -1 0 1 0 -1 -1 0 0 1 0 -1;
0 -1 1 1 0 0 -1 -1 1 1 0 -1 -1 1 0 -1 1 0 -1 0 0 1 0;
0 -1 -1 0 1 0 0 1 0 1 0 0 -1 1 0 1 1 0 -1 0 -1 0 -1;
1 1 -1 1 -1 0 0 0 -1 1 0 0 -1 0 -1 -1 -1 0 1 1 1 1 0];
sz = size(A)
sz = 1×2
21 23
g = graph(A, 'upper');
Error using graph
Haya Ali on 25 May 2023
23 by 23
Steven Lord on 25 May 2023
A = rand(23, 23) < 0.25; % Random adjacency matrix with roughly 25% nonzeros
nnz(A)./numel(A)
ans = 0.2533
g = graph(A, 'upper');
plot(g)