Plotting a complete multipartite graph

5 ビュー (過去 30 日間)
Asha Sunilkumar
Asha Sunilkumar 2020 年 8 月 26 日
編集済み: Lennart Sinjorgo 2020 年 11 月 9 日
How can we plot a complete multipartite graph K 2,2,3,4 and label its vertices in Matlab?

回答 (1 件)

Lennart Sinjorgo
Lennart Sinjorgo 2020 年 11 月 9 日
編集済み: Lennart Sinjorgo 2020 年 11 月 9 日
The adjacency matrix of the complete multipartite graph is mostly a matrix of all ones. Except on the diagonal there are blocks of zero matrices. The zero matrices blocks have sizes of the partitions. I added a function below which does the job. Not really optimzed but no problem for such a question.
function [Adj] = CompleteMultipartite(Partitions)
% Enter the Partitions as row or column vector
% Adjacency of K_{2,3,4} would be CompleteMultipartite([2 3 4])
Rows = size(Partitions,1);
if Rows == 1
Partitions = Partitions' ;
end
SumPartitions = sum(Partitions,1);
Adj = ones(SumPartitions, SumPartitions);
n = length(Partitions);
Adj(1:Partitions(1),1:Partitions(1)) = zeros(Partitions(1),Partitions(1));
for i = 2:n
IntervalEnd = sum(Partitions(1:i),1);
IntervalStart = sum(Partitions(1:(i-1),1))+1;
IntervalSize = IntervalEnd - IntervalStart +1;
Adj(IntervalStart:IntervalEnd,IntervalStart:IntervalEnd) = zeros(IntervalSize,IntervalSize);
end
end

カテゴリ

Help Center および File ExchangeNetworks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by