[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: elementwise boolean operations
From: |
Jaroslav Hajek |
Subject: |
Re: elementwise boolean operations |
Date: |
Fri, 21 May 2010 20:54:40 +0200 |
On Thu, May 20, 2010 at 8:07 PM, Przemek Klosowski
<address@hidden> wrote:
> On 05/20/2010 01:49 PM, Judd Storrs wrote:
>
>> I think& and | will do what you want. There are functional forms too:
>> and(), or(), xor(), etc. The functional forms can take multiple
>> inputs.
>
> 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.
>
> x=[0 1 0 1; 0 0 1 1]
> x =
>
> 0 1 0 1
> 0 0 1 1
>
> xor(x(1,:),x(2,:))
> ans =
>
> 0 1 1 0
>
>
In 3.3.51+, one possible option is to use bitunpack:
octave:1>N = 4; reshape (bitunpack (int32 (0:2^N-1)),32,[])'(:,N:-1:1)
ans =
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz