conncomp
Connected graph components
Description
uses additional options specified by one or more Name-Value pair arguments. For example,垃圾箱
= Conncomp(G
,,,,姓名,,,,Value
)conncomp(G,'OutputForm','cell')
返回单元格数组来描述连接的组件。
Examples
Find Graph Components
创建并绘制具有三个连接组件的无向图。采用conncomp
to determine which component each node belongs to.
g =图([1 1 4],[2 3 5],[1 1 1],6);图(g)
bin = Conncomp(G)
bin =1×61 1 1 2 2 3
Strong and Weak Graph Components
创建并绘制有向图,然后计算强连接的组件和弱连接的组件。弱连接的组件忽略了连接边缘的方向。
s = [1 2 2 3 3 3 4 5 5 5 8 8];t = [2 3 4 1 4 5 5 3 6 7 9 10];g = digraph(s,t);情节(g,'布局',,,,'layered')
str_bins = Conncomp(G)
str_bins =1×104 4 4 4 4 6 5 1 3 2
feek_bins = conncomp(g,'Type',,,,'虚弱的')
feek_bins =1×101 1 1 1 1 1 1 1 2 2 2
根据大小丢弃图形组件
采用the second output ofconncomp
to extract the largest component of a graph or to remove components below a certain size.
Create and plot a directed graph. The graph has one large component, one small component, and several components that contain only a single node.
s = [1 2 2 3 3 3 4 5 5 5 8 8 9];t = [2 3 4 1 4 5 5 3 6 7 9 10 10];g = digraph(s,t,[],20);情节(g,'布局',,,,'layered')
计算弱连接的组件,并将两个输出指定为conncomp
获取每个组件的大小。
[bin,binsize] = conncomp(g,'Type',,,,'虚弱的')
bin =1×201 1 1 1 1 1 1 1 2 2 23 4 5 6 7 8 9 10 11 12
binsize=1×127 3 1 1 1 1 1 1 1 1 1 1 1
采用binsize
从图中提取最大的组件。IDX
一世s a logical index indicating whether each node belongs to the largest component. Thesubgraph
function extracts the nodes selected byIDX
fromG
。
idx = binsize(bin)== max(binsize);SG =子图(G,IDX);情节(SG)
类似的用途binsizes
是根据大小过滤组件。该过程类似于提取最大的组件,但是在这种情况下,每个节点都可以属于满足大小需求的任何组件。
滤除任何组件G
少于3个节点。IDX
是一个逻辑索引,指示每个节点是否属于具有3个或更多节点的组件。
IDX= binsize(bin) >= 3; SG = subgraph(G, idx); plot(SG)
Input Arguments
名称值参数
Specify optional pairs of arguments asname1 = value1,...,namen = valuen
,,,,where姓名
是参数名称和Value
一世s the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名
用引号。
Example:bin = conncomp(g,'outputform','cell')
输出Form
-输出类型
'向量'
(默认)|'cell'
输出类型,,,,specified as the comma-separated pair consisting of“输出形式”
and either'向量'
or'cell'
。
Option | 输出 |
---|---|
'向量' (default) |
垃圾箱 一世s a numeric vector indicating which connected component each node belongs to. |
'cell' |
垃圾箱 是一个单元格数组,垃圾箱{J} 包含属于组件的所有节点的节点IDj 。 |
Type
-连接组件的类型
'strong'
(默认)|'虚弱的'
笔记
这'Type'
option is supported only for directed graphs created usingdigraph
。
连接组件的类型,指定为逗号分隔对'Type'
and either'strong'
(默认)或'虚弱的'
。
Option | Result |
---|---|
'strong' (default) |
两个节点属于相同的连接组件bothdirections. |
'虚弱的' |
如果有一个路径连接它们,忽略边缘方向,则两个节点属于相同的连接组件。 |
Example:bin =conncomp(G,'Type','weak')
computes the weakly connected components of directed graphG
。
输出参数
垃圾箱
-Connected components
向量|单元阵列
连接的组件,返回为矢量或单元格数组。垃圾箱编号将图中的每个节点分配给连接的组件:
If
输出Form
一世s'向量'
(default), then垃圾箱
是一个数字向量,指示每个节点属于哪个连接的组件(bin)。If
输出Form
一世s'cell'
, 然后垃圾箱
是一个单元格阵列,带有垃圾箱{J}
containing the node IDs for all nodes that belong to componentj
。
binsizes
- 每个连接组件的大小
向量
Size of each connected component, returned as a vector.布局(i)
gives the number of elements in component一世
。长度binsizes
一世s equal to the number of connected components,max(bins)
。
更多关于
Weakly Connected Components
如果有一个连接它们的路径(忽略边缘方向),则两个节点属于相同的弱连接组件。两个弱连接的组件之间没有边缘。
这concepts of strong and weak components apply only to directed graphs, as they are equivalent for undirected graphs.
紧密连接的组件
如果有两个方向连接的路径,则两个节点属于相同的强连接组件。两个强烈连接的组件之间可以存在边缘,但是这些连接边缘绝不是周期的一部分。
固定连接组件的bin数字使得连接两个组件的任何边缘从较小的bin编号的组件连接到具有较大bin号的组件的组件。
这concepts of strong and weak components apply only to directed graphs, as they are equivalent for undirected graphs.
扩展功能
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
这name-value argument
“输出形式”,,,,'cell'
that specifies cell array output is not supported.
版本历史记录
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
您单击了与此MATLAB命令相对应的链接:
运行该命令通过输入MATLAB逗号nd Window. Web browsers do not support MATLAB commands.
Select a Web Site
选择一个网站以获取可用的翻译内容,并查看本地事件和优惠。根据您的位置,我们建议您选择:。
You can also select a web site from the following list:
如何获得最佳网站性能
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
Americas
- América Latina(Español)
- Canada(English)
- United States(English)