constructing a bipartite graph from 0/1 matrix

조회 수: 48 (최근 30일)
R yan
R yan 2016년 4월 6일
댓글: kalaiyarasan V 2022년 12월 7일
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
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
Josh Carmichael
Josh Carmichael 2020년 12월 4일
Mike already decomposed the graph, it was the big_a command.
Chetan Annam
Chetan Annam 2021년 7월 14일
Hi,
I don't understand how this h.XData, h.YData works. Please help me.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by