How to graph adjacency matrix using MATLAB

前端 未结 3 1410
暖寄归人
暖寄归人 2021-01-05 01:25

I want to create a plot showing connections between nodes from an adjacency matrix like the one below.

\"enter

3条回答
  •  迷失自我
    2021-01-05 01:42

    If your graph is connected, a way to construct the array xy to pass to gplot is as v(:,[2 3]) where v is the matrix of eigenvectors of the Laplacian matrix, ordered from smallest eigenvalues to largest. So we can do it this way:

    L=diag(sum(A))-A;
    [v,~]=eig(L);
    xy=v(:,[2 3])
    gplot(A,xy)
    

    or this way:

    L=diag(sum(A))-A;
    [v,~]=eigs(L,3,'SM')
    xy=v(:,[2 1])
    gplot(A,xy)
    

    The second one should be more efficient, especially if A is big.

    This will create a nice plot under normal circumstances. This is not guaranteed to work; in particular, it is not guaranteed to assign different nodes different coordinates. But usually it works pretty nicely.

    Some theory behind this can be found at https://arxiv.org/pdf/1311.2492.pdf

提交回复
热议问题