0
$\begingroup$

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})}], "]"}]. >>

$\endgroup$
5
$\begingroup$

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}]
$\endgroup$

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.