The following will work for input matrices of width of 10 or less, due to the usage of dec2base to generate the various column combinations:
in = [100, 60, 20;, 50, 30, 10; 700, 500, 200];
assert(size(in, 2) <= 10, 'input matrix is too wide');
numperms = size(in, 2) ^ size(in, 1);
colselect = dec2base(0:numperms-1, size(in, 2)) - '0' + 1;
rowselect = repmat(1:size(in, 1), numperms, 1);
out = in(sub2ind(size(in), rowselect, colselect))
For larger matrices (but the number of permutations may be prohibitively high), it's possible to generate the combinations with ndgrid:
colcombs = cell(1, size(in, 1));
[colcombs{:}] = ndgrid(1:size(in, 2));
colcombs = cellfun(@(c) c(:), colcombs, 'UniformOutput', false);
colselect = [colcombs{:}];
Best Answer