Draw network or graph from matrix in matlab

后端 未结 1 646
慢半拍i
慢半拍i 2020-12-09 23:38

How do I draw a sequence of frames of a network with the help of a transition matrix? I have a matrix that denotes a graph. The matrix changes with iterations. Can anyone gi

相关标签:
1条回答
  • 2020-12-10 00:17

    This question is related to this earlier query and this one. But here's an answer specific to your situation.

    Given a weighted adjacency matrix:

     original =    [0.06    0.57    0.37    0       0;
                    0.57    0.06    0.37    0       0;
                    0.37    0.57    0.03    0.03    0;
                    0       0       0.03    0.13    0.84;
                    0       0       0       0.84    0.16];
    

    you can first define the number of nodes in the network:

    N = size(original,1);
    

    and then a corresponding set of coordinates on the perimeter of a circle:

    coords = [cos(2*pi*(1:N)/N); sin(2*pi*(1:N)/N)]';
    

    Then you can plot the graph using gplot:

    gplot(original, coords)
    

    and mark the vertices using text:

    text(coords(:,1) - 0.1, coords(:,2) + 0.1, num2str((1:N)'), 'FontSize', 14)
    

    Note that the gplot function does not weight the lines by connection strength; the matrix element (i,j) is treated as binary, indicating absence or presence of a link between nodes i and j.

    0 讨论(0)
提交回复
热议问题