%Calculate incidence matrix from adjacency matrix of a graph %n = order, e = size of graph %this file should be called incid.m, same as the function for this to work. %usage: M=incid(n,A); function M=incid(n,A) e=0; for i=1:n, for j=1:n, if A(i,j)==1 e=e+1; M(i,e)=1; %1st subscript is row label, ie vertex number M(j,e)=1; %second subscript is edge number end; end; end; %display(M); %note that increasing e stepwise increases the size of the matrix M stepwise. %this is inefficient for large e, there it would be better to estimate or calculate e %beforehand.