Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;

{{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

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

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.