Phorce
Phorce

Reputation: 4652

Matlab - Plotting Graph Vertex and Edges

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?

enter image description here

Upvotes: 1

Views: 1687

Answers (2)

Nitish
Nitish

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:

enter image description here Note: The figure you have pasted as sample doesn't correspond to the Matrix you have provided.

Upvotes: 1

Rafael Monteiro
Rafael Monteiro

Reputation: 4549

You could try wgPlot or gplotwl.

Upvotes: 1

Related Questions