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 visualización (últimos 30 días)
please keep in mind 1 and 2 is different combination and 2 and 1 is different combination.

Respuesta aceptada

Guillaume
Guillaume el 7 de Ag. de 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 comentarios
Guillaume
Guillaume el 7 de Ag. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by