constructing a bipartite graph from 0/1 matrix
21 次查看(过去 30 天)
显示 更早的评论
hi,
I have a 0/1 matrix H of size m by n. I want to create a bipartite graph G such that:
G has m+n vertices. One partition of G contains m vertices (corresponding to rows). Another partition contains n vertices (corresponding to columns). There will be an edge between i(from partition 1) and j (from partition 2) if H(i,j)=1 . Please suggest some approach. thanks
采纳的回答
Mike Garrity
2016-4-6
Perhaps something like this?
% Make a random MxN adjacency matrix
m = 3
n = 5
a = rand(m,n)>.25;
% Expand out to symmetric (M+N)x(M+N) matrix
big_a = [zeros(m,m), a;
a', zeros(n,n)];
g = graph(big_a);
% Plot
h = plot(g);
% Make it pretty
h.XData(1:m) = 1;
h.XData((m+1):end) = 2;
h.YData(1:m) = linspace(0,1,m);
h.YData((m+1):end) = linspace(0,1,n);
3 个评论
更多回答(0 个)
另请参阅
类别
在 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!