guskenny83
guskenny83

Reputation: 1373

Can I extract coordinate information from biograph object in MATLAB?

I have an adjacency matrix without coordinates that I would like to represent nicely using gplot.

I am able to get it to show as a biograph object with a good spacing between all the nodes, so I was wondering if there was a way to extract the coordinates from the biograph object to then use with gplot?

EDIT:
I got some negative feedback (with no comments) about this question for some reason, so I will try to elaborate further.

The data I am using is for a graph represented as a weighted adjacency matrix. I would like to be able to display it using the gplot function in MATLAB, however gplot requires cartesian coordinates for each vertex, information that I haven't been given.

I don't really want to have to go to the trouble of using a force directed graph algorithm to calculate the coordinates in order to display the graph, because that would be overkill, I just want a way to display the graph so that the vertices aren't completely randomly distributed.

An easy way to do this is to use the biograph function like so:

G = <adjacency matrix>
ids = <vertex labels>

bg = biograph(G,ids,'ShowArrows','off','ShowWeights','on',...
    'EdgeType','straight','LayoutType','equilibrium');

h=view(bg);

which displays a reasonable looking representation of the graph, however I would like it if I didn't have to use the biograph environment and I could use the gplot one instead.

The MATLAB documentation says that to find the x-y coordinates of node 3 (for example) I can use:

bg.nodes(3).Position

to query the position of the node; however when do that it returns [ ]

strangely though, if I double click on a node in the graphical representation I can access this information in the pop up window, so I am sure it exists somewhere..

Does anyone have any idea of how I can extract this information from a biograph object? I just need a n*2 matrix with the x and y coordinates for each vertex.

Sorry if my original question was too vague, I hope this is better

Upvotes: 0

Views: 193

Answers (1)

guskenny83
guskenny83

Reputation: 1373

For anyone who is looking for the answer to this question, the original biograph object does not contain the position information, this is only calculated once the object is viewed - so in order to find the information you need to reference the figure handle, not the original object. This can be done using:

h.nodes(3).Position

Upvotes: 1

Related Questions