Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
determine changes from 0 to 1 in a logical vector

Subject: determine changes from 0 to 1 in a logical vector

From: angelina

Date: 5 Apr, 2013 10:44:07

Message: 1 of 4

hi!
I would like to count the times ,the elements of a logical vector change from 1 to 0.
For example, for the following vector:
[0 1 1 0 1 1 1 0 ] the elements change two times from 1 to 0.
Any tip would be useful!!
Thank you!

Subject: determine changes from 0 to 1 in a logical vector

From: angelina

Date: 5 Apr, 2013 10:56:05

Message: 2 of 4

"angelina" wrote in message <kjm9tn$a2o$1@newscl01ah.mathworks.com>...
> hi!
> I would like to count the times ,the elements of a logical vector change from 1 to 0.
> For example, for the following vector:
> [0 1 1 0 1 1 1 0 ] the elements change two times from 1 to 0.
> Any tip would be useful!!
> Thank you!

Guys , I just found it!Sorry for posting!
thanks!

Subject: determine changes from 0 to 1 in a logical vector

From: dpb

Date: 5 Apr, 2013 14:11:35

Message: 3 of 4

On 4/5/2013 5:56 AM, angelina wrote:
> "angelina" wrote in message <kjm9tn$a2o$1@newscl01ah.mathworks.com>...
>> hi!
>> I would like to count the times ,the elements of a logical vector
>> change from 1 to 0.
>> For example, for the following vector:
>> [0 1 1 0 1 1 1 0 ] the elements change two times from 1 to 0.
>> Any tip would be useful!!
>> Thank you!
>
> Guys , I just found it!Sorry for posting!


Good...since you didn't post your solution, for comparison here's one...

nnz(diff([0 1 1 0 1 1 1 0])==-1)

--

Subject: determine changes from 0 to 1 in a logical vector

From: angelina

Date: 5 Apr, 2013 18:30:13

Message: 4 of 4

dpb <none@non.net> wrote in message <kjmm2n$cgr$1@speranza.aioe.org>...
> On 4/5/2013 5:56 AM, angelina wrote:
> > "angelina" wrote in message <kjm9tn$a2o$1@newscl01ah.mathworks.com>...
> >> hi!
> >> I would like to count the times ,the elements of a logical vector
> >> change from 1 to 0.
> >> For example, for the following vector:
> >> [0 1 1 0 1 1 1 0 ] the elements change two times from 1 to 0.
> >> Any tip would be useful!!
> >> Thank you!
> >
> > Guys , I just found it!Sorry for posting!
>
>
> Good...since you didn't post your solution, for comparison here's one...
>
> nnz(diff([0 1 1 0 1 1 1 0])==-1)
>
> --mine was a bit 'silly' solution.
for every two elements of the vector, if the first element of the couple is 1 and the sum of the couple is 1 ,I increment a variable A by 1 (A=A+1)

Tags for this Thread

No tags are associated with this thread.

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.

Contact us