How can I create this matrix?

1 visualizzazione (ultimi 30 giorni)
Sourasis Chattopadhyay
Sourasis Chattopadhyay il 4 Ago 2021
Commentato: Walter Roberson il 19 Ago 2021

Risposta accettata

Stephen23
Stephen23 il 4 Ago 2021
n = 5;
r = 2:5;
F = @(k)any(permute(nchoosek(1:n,k),[3,1,2])==(1:n).',3);
M = cell2mat(arrayfun(F,r,'uni',0))
M = 5×26 logical array
1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 0 1 1 0 1 0 0 1 0 0 1 1 0 1 0 0 1 1 0 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 0 1 0 1 0 1 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 0 0 1 0 0 1 0 1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 1
  4 Commenti
Sourasis Chattopadhyay
Sourasis Chattopadhyay il 19 Ago 2021
Thank you for you answer .
Walter Roberson
Walter Roberson il 19 Ago 2021
You might be able to fit the 50 case. Change to
F = @(k)any(permute(nchoosek(uint8(1:n),k),[3,1,2])==uint8(1:n).',3);

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by