Plot graph with large dataset
显示 更早的评论
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
2017-5-23
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 个评论
Thanks alot for your answer. Can I convert into a simple graph?
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.
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?
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
Then, how can we generate a connected graft by using random source and destination node?
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
