Reputation: 4652
Basically, I'm starting to learn graph theory and I want to plot an undirected graph and cannot find anywhere that specifically has an implementation for this in Matlab. I have the following matrix:
G = [0, 0, 1; 0, 0, 1; 1, 1, 0];
How would I therefore plot this, to get the result of below?
Upvotes: 1
Views: 1687
Reputation: 7196
You can use gplot
where you specify only the Adjacency Matrix and the Coordinates of the Nodes.
G = [0, 0, 1; 0, 0, 1; 1, 1, 0];
xy = [1 1; 0 0 ; 2 0];
gplot(G,xy,'-o');
axis([-1 3 -1 3]) % To Centre the Figure
If you want to make it look fancier, you can play with the Thickness and stuff as:
hline = findobj(gcf, 'type', 'line');
set(hline,'LineWidth',3)
Which gives:
Note: The figure you have pasted as sample doesn't correspond to the Matrix you have provided.
Upvotes: 1