Combinations from a given set without repetition

matlab, matrix

Solution

This is the simplest way I've come up with:

n = size(M, 2);
[j, i] = ind2sub([n n], find(~triu(ones(n))));
ResultVec = M(:, [i j]);
ResultVec = reshape(ResultVec, [], 2)

Problem

Suppose I have a matrix defined as follows ``` M = [C1 C2 C3 C4] ``` Where the C's are column vectors I want some efficient (i.e. no for loops) way of producing A vector such that ``` ResultVec = [C1 C2; C1 C3; C1 C4; C2 C3; C2 C4; C3 C4] ``` Thanks in advance!

Original source