help-octave
[Top][All Lists]
Advanced

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

Re: elementwise boolean operations


From: Judd Storrs
Subject: Re: elementwise boolean operations
Date: Thu, 20 May 2010 14:25:06 -0400

On Thu, May 20, 2010 at 2:07 PM, Przemek Klosowski
<address@hidden> wrote:
> Actually, I was just wondering about that. I wanted a truth table of
> a complicated logical expression, and I wrote it by a nested for bit=0:1
> loop; but there must be a better way. Given that the logical ops take
> vector arguments, all I need is a concise way to create a N by 2^N
> vector with all bit combinations, i.e.

I don't know about Gray coding but you can create arbitrary nests
of input vectors using ndgrid. For example if you needed all possible
permutations of four binary variables

bits = logical(0,1);
[a,b,c,d] = ndgrid(bits,bits,bits,bits);

[a(:), b(:), c(:), d(:)]

   0   0   0   0
   1   0   0   0
   0   1   0   0
   1   1   0   0
   0   0   1   0
   1   0   1   0
   0   1   1   0
   1   1   1   0
   0   0   0   1
   1   0   0   1
   0   1   0   1
   1   1   0   1
   0   0   1   1
   1   0   1   1
   0   1   1   1
   1   1   1   1


--judd


reply via email to

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