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 次查看(过去 30 天)
please keep in mind 1 and 2 is different combination and 2 and 1 is different combination.

采纳的回答

Guillaume
Guillaume 2018-8-7
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 个评论
Guillaume
Guillaume 2018-8-7
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sparse Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by