Search code examples
matlabgraphplotgplots

matlab draw a graph from the incidence matrix


Is there a way to draw a graph from the Incidence matrix. By graph I mean http://en.wikipedia.org/wiki/Graph_(mathematics) not a plot.

Up till now I found only how to convert incidence matrix to a adjacency matrix. In R this is possible with an igraph library. So is there an easy way to do it in matlab


Solution

  • You may use gplot:

    k = 1:30;
    [B,XY] = bucky;
    gplot(B(k,k),XY(k,:),'-*')
    axis square
    

    This function is commonly used in machine learning problems. While searching up I've seen an implementation for weighted graph plotting.

    enter image description here http://www.mathworks.com/help/matlab/ref/gplot.html

    EDIT:

    dt = 2*pi/10;
    t = dt:dt:2*pi;
    x = cos(t); y = sin(t);
    A = ones(10);
    gplot(A,[x' y']);
    A = ones(3,3);
    gplot(A,[x' y']);
    a = [0 1 1; 1 0 0; 1 1 0];
    gplot(a,[x' y'] ,'-*');
    

    All you have to do is make sure the XY plane has sufficient (x,y) pairs for each node in your graph.

    Here is A's gplot:

    enter image description here