Gml to Graphs

  • Follow


Hi all:
I am trying to read the gml file in matlab so that it can be converted into adjacency matrix representation of graphs. Can anybody help me in resolving this.

Thanks
Rahul Singhal
0
Reply Rahul 1/11/2010 9:19:04 AM

"Rahul Singhal" <rsinghalomatic@gmail.com> wrote in message <hieqe8$iab$1@fred.mathworks.com>...
> Hi all:
> I am trying to read the gml file in matlab so that it can be converted into adjacency matrix representation of graphs. Can anybody help me in resolving this.
> 
> Thanks
> Rahul Singhal

I had the same problem, but I solved it naively, not robust at all, but worked for me.. taking for example the Zachary's Karate club network (http://www-personal.umich.edu/~mejn/netdata/) , I used the following code:
fileName = 'karate.gml';
inputfile = fopen(fileName);
A=[];

l=0;
k=1;
while 1

    % Get a line from the input file
    tline = fgetl(inputfile);

    % Quit if end of file
    if ~ischar(tline)
        break
    end
    
    nums = regexp(tline,'\d+','match'); %get number from string
    if length(nums)
        if l==1
            l=0;
            A(k,2)=str2num(nums{1});  
            k=k+1;
            continue;
        end
        A(k,1)=str2num(nums{1});
        l=1;
    else
        l=0;
        continue;
    end   
end

A[] will finally contain the links between nodes, and easy to change to adjacency matrix.
0
Reply shamieh_m (1) 4/28/2012 11:47:43 AM


1 Replies
566 Views

(page loaded in 0.056 seconds)

Similiar Articles:





7/24/2012 6:16:37 AM


Reply: