Implement a directed Graph as an undirected graph using GraphX - scala

I have following directed graph as given by the nodes and edges below.
Nodes
1,2,3,4,5
Edges
(1,2),(1,3),(1,4),(2,5),(3,4),(3,5),(4,5)
How do I convert this directed graph to undirected graph
Do I have to convert using built-in method. If there is build in method, what method is it?.
Or, do I have to add edges manually in the dataset such as (1,2) to (2,1).

You don't need to convert your graph to an undirected graph. You'll simply have to treat it as an undirected graph (by simply ignoring the edge directions).
For example, if you use collectNeighbors, you can make it act as an undirected graph by passing an EdgeDirection.Either as parameter.

Related

Is there XY Graph block in Xcos

In Simulink, there is an XY Graph block. Is there a similar block in Xcos?
I work in Xcos. When I use CScope in my model, I get a graph showing either s-t (coordinate-time) or v-t (speed-time) dependency. But I need my s and v to be the axes of the graph (I need to show how speed depends on the coordinate). In Simulink, I should use the XY Graph block. How can I do it in Xcos?
Use the CSCOPXY block (in the Sinks Palette).

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
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

plot large graph in matlab

I want to plot a graph with more than 5000 nodes in Matlab.
I'm using biograph and view function for this command but after some executing Matlab show this error:
The layout engine cannot generate this graph,
try other layout types or reduce the number of nodes.
I'm try other layout types but give me same error.

Set Matlab's Contour graph x-axis scale?

I am trying to graph a contour graph with a two dimentional matrix, v. v contains velocity data, y-index represents depth, x-index is mapped to a 1d-vector containing latitude info, lat.
when I graph contour(v), the x-axis is index, but I wish to show the latitude (also scale accordingly), I tried contour(lat,v) but it just shows me a blank graph, how should I graph it?
Without having an example dataset, it's hard to say for sure... but I suspect that what you need to do is use the contour(X,Y,Z) form of contour. If you want to specify one axis, you need to specify both. In your case, it would be:
contour(lat,depth,v)
If you're happy using the y-index rather than an actual depth vector, you can do
contour(lat,1:size(v,2),v)

CGAL 2D Delaunay Triangulation: How to get all the edges

How to get/iterate over all the edges in the 2D delaunay graph in CGAL (C++)?
For example, in MATLAB this is just edges(dt).
You simply need to use members functions
All_edges_iterator all_edges_begin()
All_edges_iterator all_edges_end()
to get the iterator range over edges.
It is documented on the Triangulation_2 page here
Note that you will get edges incident to the infinite vertex together with finite edges.