[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: create matrix with all possible combinations
From: |
Joshua Stults |
Subject: |
Re: create matrix with all possible combinations |
Date: |
Mon, 2 Nov 2009 21:04:15 -0500 |
On Mon, Nov 2, 2009 at 7:43 PM, xeon <address@hidden> 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?
Perhaps nchoosek() will give you what you want:
n = [ones(8,1); zeros(8,1)];
A = nchoosek(n, 8);
The size of a matrix created this way can grow very large very
quickly; calling nchoosek() with a scalar will give you the number of
combinations:
nchoosek(16, 8)
ans = 12870
--
Joshua Stults
Website: http://j-stults.blogspot.com