igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Re: igraph in MatLab


From: Mark McClure
Subject: Re: [igraph] Re: igraph in MatLab
Date: Tue, 24 Mar 2009 06:37:39 -0400

From: "Ch-Y" <address@hidden>
I’m a student of University  of Iowa.  I want to use the c library of igraph in the MatLab.  Could you tell me how to convert the igraph data type into the standard c data type?

I'm working on a similar project for Mathematica so I might be able to answer the question.  I assume that you are using Matlab's Mex facility to call the igraph library from Matlab and the Mex API functions expect ordinary C arrays to transfer data in and out of Matlab.  First, you'll need to choose an appropriate way to represent the data you want to transfer as a matrix.  A graph with m edges might be represented as an m by 2 integer matrix where each row represents an edge.  My code to store the edges of an igraph igraph_t to such a matrix is as follows:

     igraph_es_t es;                  // Edge selector
     igraph_eit_t eit;                // Edge iterator
     igraph_integer_t eid, from, to;  // Edge id and from/to nodes.
    
     (void) igraph_es_all(&es, IGRAPH_EDGEORDER_ID);
     (void) igraph_eit_create(&graph, es, &eit);
     int len = (int) IGRAPH_EIT_SIZE(eit);
     int result[len][2];
    
     // Iterate through the edges and store them in result.
     int i = 0;
     while (!IGRAPH_EIT_END(eit)) {
          eid = IGRAPH_EIT_GET(eit);
          igraph_edge(&graph, eid, &from, &to);
          result[i][0] = (int) from;
          result[i][1] = (int) to;
          i = i+1;
          IGRAPH_EIT_NEXT(eit);
     }

Hope that helps,
Mark McClure


reply via email to

[Prev in Thread] Current Thread [Next in Thread]