How can I create this matrix?

1 Ansicht (letzte 30 Tage)
Sourasis Chattopadhyay
Sourasis Chattopadhyay am 4 Aug. 2021
Kommentiert: Walter Roberson am 19 Aug. 2021
  1 Kommentar
KSSV
KSSV am 4 Aug. 2021
An example will hep us to help you.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Stephen23
Stephen23 am 4 Aug. 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 Kommentare
Sourasis Chattopadhyay
Sourasis Chattopadhyay am 19 Aug. 2021
Thank you for you answer .
Walter Roberson
Walter Roberson am 19 Aug. 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);

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by