help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: create matrix with all possible combinations


From: Ben Abbott
Subject: Re: create matrix with all possible combinations
Date: Mon, 02 Nov 2009 21:05:09 -0500


On Nov 2, 2009, at 7:43 PM, xeon wrote:

Hi,

I would like to create a matrix with 8 columns with all possible
combinations with the values 0 and 1 in Octave.

For example,
[0,0,0,0,0,0,0,0;1,0,0,0,0,0,0,0;0,1,0,0,0,0,0,0;...;1,1,1,1,1,1,1,1];

How can I do that?

thanks,

The may be a better way, but you can accomplish what you want by ...

        n = 8;
        a = dec2bin ([0:2^n-1], n);
        b = num2cell (a(:), 2);
        c = cellfun (@(x) eval(x), b);
        d = reshape (c, [2^n, n])

Ben


reply via email to

[Prev in Thread] Current Thread [Next in Thread]