Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a dataset in format .txt of a directed network, containing a matrix A of dimension m x 2, where each row gives the labels of two nodes showing a direct link.

For example, when the network has $4$ nodes, the matrix A could be

A = [1 2; 1 3; 2 1; 2 4; 3 2; 4 1; 4 2]

where the first row means that there is a link from 1 to 2, the second row means that there is a link from 1 to 3, etc.

Could you suggest me a way to draw the network specified by A in Mathematica?

share|improve this question
Probably you can do: DirectedEdge @@@ Import["text.txt", "Data"] // Graph. Please take a look at all those symbols in documentation if there are doubts. –  Kuba May 22 at 11:20
I guess you're aware that your line of code is NOT valid in Mathematica. –  belisarius May 22 at 11:37
add comment

1 Answer 1

First you need to get a minimum involved in what you are planning to do and search for "network" inside Mathematica:


Then you want to construct a Graph so you go to:


and see: Graph — construct a graph from vertices and edges:


where the first example is:

Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}]

Mathematica graphics

So hey! Why not giving the same structure to A:

A = {1 -> 2, 1 -> 3, 2 -> 1, 2 -> 4, 3 -> 2, 4 -> 1, 4 -> 2}

Mathematica graphics

Regarding the Import part (like Kuba suggested):

mat = First@ToExpression@Import["http://pastebin.com/raw.php?i=tVXqhVgD", "Data"]
Graph[DirectedEdge @@@ mat]
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.