How to convert a graph to adjacency matrix?

Hi. I've created a graph G in MATLAB. But when I type A = adjacency(G), I get this error:
Unable to use a value of type 'graph' as an index.

1 Comment

Can you share an example code that can recreate this error?

Sign in to comment.

 Accepted Answer

You've created a variable named adjacency that is taking precedence over the adjacency method for graph objects. Rename the variable.

2 Comments

s = {'1' '2'};
t = {'2' '3'};
G = graph(s,t);
A = adjacency(G);
This is my code, I'm still getting the same error
Can you show the output of
which graph
which adjacency

Sign in to comment.

More Answers (0)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!