I asked this question in different form and because I couldn't receive the proper answer so I have to change my question.I know that was my fault sorry. I need to change the Matrix Data of nodes and edges in the graph. How can I do that on the graph itself by clicking on each node?

Graph[{"Uppsala" -> "Marsta", "Marsta" -> "Uppsala", 
  "UpplandsVasby" -> "Sollentuna", "Sollentuna" -> "UpplandsVasby", 
  "UpplandsVasby" -> "Marsta", "Marsta" -> "UpplandsVasby", 
  "Stockholm" -> "Boo", "Boo" -> "Stockholm", 
  "Stockholm" -> "Lidingo", "Lidingo" -> "Stockholm", 
  "Stockholm" -> "Sollentuna", "Sollentuna" -> "Stockholm", 
  "Stockholm" -> "Taby", "Taby" -> "Stockholm"}, 
 EdgeWeight -> RandomInteger[{10, 100}, 14] 
 VertexLabels -> "Name"]
  • $\begingroup$ What is Matrix Data? $\endgroup$ – Dr. belisarius May 13 '13 at 14:03
  • $\begingroup$ You can't do it by clicking on each node. You need to enter commands to set these properties. The command to look up is SetProperty. $\endgroup$ – Szabolcs May 13 '13 at 14:04
  • 1
    $\begingroup$ Can you clarify if your question is about how to set the weights, or about how to set the weights using a graphical point-and-click interface? $\endgroup$ – Szabolcs May 13 '13 at 14:09

The function to use to set properties on graphs is SetProperty. Sometimes this function can be a bit inconsistent and difficult to figure out, but this time the standard syntax works:

SetProperty[{g, "Uppsala" \[DirectedEdge] "Marsta"}, EdgeWeight -> 15]

You could also use

SetProperty[g, EdgeWeight -> {"Uppsala" \[DirectedEdge] "Marsta" -> 20}]

Note the use of \[DirectedEdge] instead of ->. You can enter it using esc de esc. Also note that SetProperty does not change the graph g. It simply return a new graph with the selected property changed. If you need to change the graph, use g = SetProperty[g, ...].

  • $\begingroup$ How can I change on the graph not in the coding?I mean in an interactive just by clicking? $\endgroup$ – Alex May 13 '13 at 14:51
  • 1
    $\begingroup$ @Alex I am not aware of any solution for that in Mathematica. You'd have to write one. You can use some other program (Gephi? Cytoscape? not sure if they can do this), construct the graph, export it to GraphML or a similar format, then import it to Mathematica. $\endgroup$ – Szabolcs May 13 '13 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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