Thread Subject: Identify singular ones in an array

Subject: Identify singular ones in an array

From: Phil

Date: 27 Aug, 2009 12:11:05

Message: 1 of 5

Hi,

I have the following data:
0
0
0
1
0
0
0
1
1
1
1
0
0

What i would like to do is identify the single 1 i.e. a singular 1 as in row four surrounded either side with a 0. The code should not identify groups of 1's i.e. those in rows 8-11.

Any help would be great.

Thanks in advance,

Phil

Subject: Identify singular ones in an array

From: dpb

Date: 27 Aug, 2009 12:49:25

Message: 2 of 5

Phil wrote:
> Hi,
>
> I have the following data: 0 0 0 1 0 0 0 1 1 1 1 0 0
>
> What i would like to do is identify the single 1 i.e. a singular 1 as
> in row four surrounded either side with a 0. The code should not
> identify groups of 1's i.e. those in rows 8-11.
...

Hint

doc diff
doc diff

--

Subject: Identify singular ones in an array

From: Phil

Date: 27 Aug, 2009 13:10:20

Message: 3 of 5

dpb <none@non.net> wrote in message <h75vkf$sig$1@news.eternal-september.org>...
> Phil wrote:
> > Hi,
> >
> > I have the following data: 0 0 0 1 0 0 0 1 1 1 1 0 0
> >
> > What i would like to do is identify the single 1 i.e. a singular 1 as
> > in row four surrounded either side with a 0. The code should not
> > identify groups of 1's i.e. those in rows 8-11.
> ...
>
> Hint
>
> doc diff
> doc diff
>
> --
This really doesn't help.

Anything else?

Thanks,

Phil

Subject: Identify singular ones in an array

From: dpb

Date: 27 Aug, 2009 13:08:09

Message: 4 of 5

dpb wrote:
> Phil wrote:
>> Hi,
>>
>> I have the following data: 0 0 0 1 0 0 0 1 1 1 1 0 0
>>
>> What i would like to do is identify the single 1 i.e. a singular 1 as
>> in row four surrounded either side with a 0. The code should not
>> identify groups of 1's i.e. those in rows 8-11.
> ...
>
> Hint
>
> doc diff
> doc diff

Or, slightly less obtuse, note the second, optional, argument to
diff()... :)

--

Subject: Identify singular ones in an array

From: dpb

Date: 27 Aug, 2009 13:26:48

Message: 5 of 5

Phil wrote:
> dpb <none@non.net> wrote in message <h75vkf$sig$1@news.eternal-september.org>...
>> Phil wrote:
>>> Hi,
>>>
>>> I have the following data: 0 0 0 1 0 0 0 1 1 1 1 0 0
>>>
>>> What i would like to do is identify the single 1 i.e. a singular 1 as
>>> in row four surrounded either side with a 0. The code should not
>>> identify groups of 1's i.e. those in rows 8-11.
>> ...
>>
>> Hint
>>
>> doc diff
>> doc diff
>>
>> --
> This really doesn't help.
...

Oh, really???

 > x = [0 0 0 1 0 0 0 1 1 1 1 0 0];
 >> find(diff(x,2)==-2)+1
ans =
      4

This relies on there being a leading zero; if that isn't assured one can
always add one and compensate.

--

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com