Permutation of columns of a matrix

Dear Octavers,

I have a matrix A composed of 4 columns C1, C2, C3 and C4.
I would like to have all the matrices (vectors) that can be generated from matrix A without repetitions of columns and where the order of the columns does not matter, i.e. matrix B = [C1 C2] = [C2 C1] . More precisely I would like to obtain the following matrices / vectors: [C1]; [C2]; [C3]; [C4]; [C1 C2]; [C1 C3]; [C1 C4]; [C2 C3]; [C2 C4 ]; [C3 C4]; [C1 C2 C3]; [C1 C2 C4]; [C1 C3 C4]; [C2 C3 C4]; [C1 C2 C3 C4].
Can we have a code that can do this task.

Thanks in advance
George

Did you have a look at the nchoosek function?
E.g. for the indices for combinations of the set of 4 columns taken 3 at a time:

nchoosek (1:4, 3)

input matrix is A

for i = 1 : 2^size(A,2)-1
A (:, dec2bin(i) == “1”)
end

This will print out all columns of A taken in 1s, 2s, 3s, … etc. Look at nchoosek or dec2bin for more.