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.

 채택된 답변

Steven Lord
Steven Lord 2017년 5월 23일

1 개 추천

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

lucksBi
lucksBi 2017년 5월 24일
Thanks alot for your answer. Can I convert into a simple graph?
Steven Lord
Steven Lord 2017년 5월 24일
편집: Steven Lord 2017년 5월 24일
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 2017년 5월 27일
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 2017년 10월 27일
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 2018년 8월 30일
Then, how can we generate a connected graft by using random source and destination node?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

질문:

2017년 5월 23일

댓글:

2018년 8월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by