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'm trying to create a simple graph from a matrix and then highlight a particular subgraph. My code (simplified from a bigger task) is as follows. I keep getting the "Subgraph::graph: A graph object is expected at position 1" message whenever I try to use Subgraph (or HighlightGraph). What might I be doing wrong? Thanks in advance for the help.

<< Combinatorica`

General::compat: Combinatorica Graph and Permutations functionality has been superseded by preloaded functionality. The package now being loaded may conflict with this. Please see the Compatibility Guide for details.

BB = Table[0, {i, 4}, {j, 4}];
BB[[1]][[2]] = 1;
BB[[2]][[1]] = 1;
BB

{{0, 1, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}

Gr = FromAdjacencyMatrix[BB];
Subgraph[Gr, {1, 2}]

Subgraph::graph: A graph object is expected at position 1 in RowBox[{"Subgraph", "[", RowBox[{InterpretationBox[StyleBox[RowBox[{"[SkeletonIndicator]", "Graph:<", 0, ",", 4, ",", "Undirected", ">[SkeletonIndicator]"}], ShowAutoStyles -> False, AutoSpacing -> False], Graph[{}, {{{0, 1.}}, {{-1., 0}}, {{0, -1.}}, {{1., 0}}}], Editable -> False], ",", ({1, 2})}], "]"}]. >>

share|improve this question
add comment

1 Answer

FromAdjacencyMatrix construct combinatorica graph. Subgraph and HighglightGraph accept system graph object.

Instead of loading Combinatorica package, you can just create graph from matrix by using AdjacencyGraph:

gr = AdjacencyGraph[BB]

Then Subgraph should work fine with it:

Subgraph[gr, {1, 2}]
share|improve this answer
add comment

Your Answer

 
discard

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.