How can I create this matrix?

조회 수: 4 (최근 30일)
Sourasis Chattopadhyay
Sourasis Chattopadhyay 2021년 8월 4일
댓글: Walter Roberson 2021년 8월 19일
  댓글 수: 1
KSSV
KSSV 2021년 8월 4일
An example will hep us to help you.

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

채택된 답변

Stephen23
Stephen23 2021년 8월 4일
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
Sourasis Chattopadhyay
Sourasis Chattopadhyay 2021년 8월 19일
Thank you for you answer .
Walter Roberson
Walter Roberson 2021년 8월 19일
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);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by