How can I generate a set containing all possible combinations?

5 Ansichten (letzte 30 Tage)
Thomas Lu
Thomas Lu am 28 Mär. 2019
Bearbeitet: Bruno Luong am 28 Mär. 2019
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!

Antworten (2)

KSSV
KSSV am 28 Mär. 2019
Read about perms
  2 Kommentare
Thomas Lu
Thomas Lu am 28 Mär. 2019
I read it and I came up with perms(combnk(1:8,4)), but the program said it exceed the sizes limit...
KSSV
KSSV am 28 Mär. 2019
v = randsample(1:8,4) ;
p = perms(v) ;
A = reshape(p',2,2,[]) ;

Melden Sie sich an, um zu kommentieren.


Bruno Luong
Bruno Luong am 28 Mär. 2019
Bearbeitet: Bruno Luong am 28 Mär. 2019
A = nchoosek(1:8,4);
A = num2cell(reshape(A',2,2,[]),[1 2]);
A = A(:);
% display
A{:}
Produces 70 2x2 matrices

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by