MATLAB: How to Generate Square Matrices with these properties?

2 vues (au cours des 30 derniers jours)
VeeVan
VeeVan le 25 Juil 2018
Commenté : Walter Roberson le 28 Juil 2018
Hello All, I was wondering how I would create a systematic Matrix Generator which goes element by element in order to generate All Graphs of Node Size 3 which have these properties:
1) All entries are a 0 or 1
2) Each Element where m = n (diagonal) must equal 0
3) There must exist at least a single "1" in each row and column
4) Entries across the diagonal must be opposite:
For example, If A(1,2) = 1 then A(2,1) must Equal 0
The generator must be able to store all of its generated graphs for later use and analysis
  2 commentaires
Walter Roberson
Walter Roberson le 25 Juil 2018
Isn't that only 8 different graphs?
VeeVan
VeeVan le 25 Juil 2018
Yes, most likely so, however, I will be expanding the program to encompass more than 3 nodes. Also, I want to congregate all the graphs as well.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 25 Juil 2018
Modifié(e) : Walter Roberson le 25 Juil 2018
N = 3;
M = N * (N-1) / 2;
numgraph = 2^M;
choices = dec2bin(0:numgraph-1, M) - '0';
graphs = cell(numgraph,1);
for K = 1 : numgraph
sq = squareform(choices(K,:));
sq = tril(1-sq) + triu(sq)
graphs{K} = digraph(sq);
end
  21 commentaires
VeeVan
VeeVan le 28 Juil 2018
Hello Walter Robertson, When I asked if we can change condition 4 for new requirements, I meant can we change the condition from "Entries across the diagonal must be opposite" to "Entries across the diagonal cannot both equal one". I believe this current code only accounts for this rule on A(1,2) and A(2,1) specifically. I apologize for any miscommunication.
Walter Roberson
Walter Roberson le 28 Juil 2018
if any( (sq + sq.') > 1 ); continue; end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by