Filter löschen
Filter löschen

i have 16 different types of files and i have to take the files in the bunch of 2 from the 16 files, how i put permutation and combination to get 2 files from the 16 files each time differently?

1 Ansicht (letzte 30 Tage)
please keep in mind 1 and 2 is different combination and 2 and 1 is different combination.

Akzeptierte Antwort

Guillaume
Guillaume am 7 Aug. 2018
Since there are only 240 combinations, it's trivial to generate them all as a 240x2 matrix:
allperms = nchoosek(1:16, 2);
allperms = [allperms; fliplr(allperms)];
You can then choose a row at random:
oneperm = allperms(randi(size(allperms, 1)), :)
or shuffle all the rows
allperms = allperms(randperm(size(allperms, 1)), :)
  4 Kommentare
Guillaume
Guillaume am 7 Aug. 2018
No, It does not extend to more than two elements. A generic version:
v = 1:16;
n = 4;
allperms = nchoosek(v, n); %all combinations
colperms = num2cell(perms(1:n), 2); %how many ways can we swap the columns
allperms = cell2mat(cellfun(@(p) allperms(:, p), colperms, 'UniformOutput', false)) %swap the columns all possible ways

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Sparse Matrices 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