How can I generate a set containing all possible combinations?

조회 수: 5 (최근 30일)
Thomas Lu
Thomas Lu 2019년 3월 28일
편집: Bruno Luong 2019년 3월 28일
Let say I want to have a 2x2 matrix and the entries are chosen from numbers 1-8 (without repetition).
How can I generate a set that contains all the possible matrices? Thanks a lot!

답변 (2개)

KSSV
KSSV 2019년 3월 28일
Read about perms
  댓글 수: 2
Thomas Lu
Thomas Lu 2019년 3월 28일
I read it and I came up with perms(combnk(1:8,4)), but the program said it exceed the sizes limit...
KSSV
KSSV 2019년 3월 28일
v = randsample(1:8,4) ;
p = perms(v) ;
A = reshape(p',2,2,[]) ;

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


Bruno Luong
Bruno Luong 2019년 3월 28일
편집: Bruno Luong 2019년 3월 28일
A = nchoosek(1:8,4);
A = num2cell(reshape(A',2,2,[]),[1 2]);
A = A(:);
% display
A{:}
Produces 70 2x2 matrices

카테고리

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

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by