Hi i want to know what does this type of graph mean? I got this while Using same code which works fine on small data but with large data it plots this graph.

 Réponse acceptée

Steven Lord
Steven Lord le 23 Mai 2017

1 vote

It means that your directed graph (stored as a digraph object) contains multiple connected components. You can see a smaller, simpler example on the documentation page for the conncomp function.

6 commentaires

lucksBi
lucksBi le 24 Mai 2017
Thanks alot for your answer. Can I convert into a simple graph?
Steven Lord
Steven Lord le 24 Mai 2017
Modifié(e) : Steven Lord le 24 Mai 2017
By "simple graph" do you mean a connected graph? There's no function to do this automatically as far as I remember but yes, you can do this. Start adding edges between two nodes that are in different connected components; each time you do, you reduce the number of components by 1. Continue until everything is in one component.
Note that there are many different ways to do this; using the example with numbered nodes on the Wikipedia page to which I linked (which is an undirected graph, not a directed graph, but the same principles apply), you could connect the node with degree 0 to any (or many, or all) of the other nodes. If you connected it to the node with degree 1, for example, you'd get something like:
% Make the graph object
s = [1 2 3 4 5 6 7 4];
t = [2 3 4 5 6 7 3 6];
G = graph(s, t);
% Generate coordinates to make it look
% something like the Wikipedia diagram
x = [0 0 1 3 5 4 2];
y = [0 2 1 2 2 1 0];
h = plot(G, 'XData', x, 'YData', y);
% Highlight the previously isolated node in red
highlight(h, 1, 'NodeColor', 'r', 'MarkerSize', 8)
% Highlight the node to which I connected it in black
highlight(h, 2, 'NodeColor', 'k', 'MarkerSize', 8)
While I connected the red highlighted node to the black highlighted node for this example, I could just as easily have connected it to any other node, like:
% Remove edge (1, 2) and add edge (1, 3)
G = rmedge(G, 1, 2);
G = addedge(G, 1, 3);
figure
h = plot(G, 'XData', x, 'YData', y);
% Highlight the previously isolated node in red
highlight(h, 1, 'NodeColor', 'r', 'MarkerSize', 8)
% Highlight the node to which I connected it in black
highlight(h, 3, 'NodeColor', 'k', 'MarkerSize', 8)
Or if you wanted you could have both connections.
G = addedge(G, 1, 2);
figure
h = plot(G, 'XData', x, 'YData', y);
highlight(h, 1, 'NodeColor', 'r', 'MarkerSize', 8);
highlight(h, [2 3], 'NodeColor', 'k', 'MarkerSize', 8)
I could continue but I think I'll stop at just three alternatives.
lucksBi
lucksBi le 27 Mai 2017
Hey thanks alot for this description i have understood the concept very clearly. I want to ask one more thing that if i have many nodes in my graph e.g. 900 nodes so i have to add and remove edges for every node separately to plot a connected graph?
bita hallajian
bita hallajian le 27 Oct 2017
How to create a graph for a large dataset in Matlab? first load the dataset, how to define nodes, edges, and weights?because we cant define source and target nodes and their weights in a large dataset, for example, creating graph for a social network
Asyran Abdullah
Asyran Abdullah le 30 Août 2018
Then, how can we generate a connected graft by using random source and destination node?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graph and Network Algorithms dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by