Nodes belongto which Graph?
2 ビュー (過去 30 日間)
古いコメントを表示
Dear matlab,
Please let me know if we can findout from the graph table which nodes belong to which graph, as in G.Edges in the graph function only shows connected nodes and linkages and weights, i.e node1 node2 weight
Can we have information that shows node and graph it belongs to, ex node1 graph1 node2 graph1 node3 graph2 node4 graph2 node5 graph2 node6 graph3
2 件のコメント
Walter Roberson
2016 年 10 月 22 日
Did you perhaps want to ask about which vertices belong to which subgraph?
Eng. Fredius Magige
2016 年 10 月 22 日
Hi An adjacency matrix (table) is pure a node to node connection. Either, movement of: TOP to RIGHT to TOP to RIGHT ..... or others are generated graphical model. whatever you want, it scientifically possible to get
回答 (1 件)
Walter Roberson
2016 年 10 月 23 日
If you have a series of graphs, G1, G2, G3, ... each of which has been created with graph(), or digraph() then:
Graphs = {G1, G2, G3, ... }; %create a cell array of all of the graphs
GraphNames = {'graph1', 'graph2', 'G3', ...}; %names of graphs to use in report
numgraph = length(Graphs);
nodes_are_numeric = false(numgraph, 1);
for K = 1 : numgraph
these_nodes = unique(Graphs{K}.Edges.EndNodes(:));
if ~iscell(these_nodes); these_nodes = num2cell(these_nodes); end
used_nodes{K} = these_nodes;
nodes_are_numeric(K) = isnumeric(these_nodes{1});
end
node_fmt_is_char = ~all(nodes_are_numeric);
if all(nodes_are_numeric) ~= any(nodes_are_numeric)
%there is a mix of node types, need to convert the numeric ones to character
for K = find(nodes_are_numeric(:)).'
used_nodes{K} = cellfun(@num2str, used_nodes{K}, 'Uniform', 0);
end
end
unique_nodes = unique( vertcat(used_nodes{:}) );
num_unique_nodes = length(unique_nodes);
node_belongs_to = cell(num_unique_nodes, 1);
for K = 1 : num_unique_nodes
this_node = unique_nodes{K};
node_is_in_graph = cellfun(@(N) ismember(this_node, N), used_nodes);
node_member_of = GraphNames(node_is_in_graph);
node_belongs_to{K} = [{this_node}, node_member_of];
end
%now the printed report
if node_fmt_is_char
fmt = 'Node %s belongs to graphs: ';
else
fmt = 'Node %g belongs to graphs: ';
end
for K = 1 : num_unique_nodes
this_entry = node_belongs_to{K};
fprintf(fmt, this_entry{1});
fprintf('%s, ', this_entry{2:end} );
fprintf('\n');
end
参考
カテゴリ
Help Center および 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!