help-octave
[Top][All Lists]
Advanced

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

Re: filtering logical array


From: Robert T. Short
Subject: Re: filtering logical array
Date: Tue, 26 Jun 2012 14:12:17 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120614 Thunderbird/13.0.1

On 06/26/2012 01:51 PM, Mike Miller wrote:
On Tue, Jun 26, 2012 at 3:53 PM, Robert T. Short
<address@hidden> wrote:
On 06/26/2012 11:48 AM, Jordi Gutiérrez Hermoso wrote:
a=[0 0 1 1 1 1 1 0 1 0 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1 1 0]
Kind of a fun problem.  Here is another solution.
More fun than what I was doing...

x = conv(a,[1 1 1])
z = x>2
z = z | shift(z,-1) | shift(z,-2)
z = z(1:length(a))

There is probably a much more elegant way to do the last two lines but it
isn't coming to me.
I noticed your shift-and-or of z is really sort of a convolution.  How about:

x = conv(a, [1 1 1])
y = conv(x, [1 1 1])
z = y >= 6
z = z(3:end-2)

Ahh!  But convolution is commutative so we can do this

y = (conv(a,conv([1 1 1],[1 1 1]))>5)(3:end-2)

8-)

Actually, if we have convolution over GF(2) the answer is cleaner but I am not aware of such a function.

Bob


reply via email to

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