From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

find the counts of consecutive 0s and 1s

Solved!
Go to solution

Hello guys--

 

I have an array contains only zeros and ones.

 

For example: A = [1,1,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,0]

 

I have created two arrays, Azeros and Aones. The Aones array holds counts of number of consecutive 1s. The Azeros array accumulates counts of consecutive 0s.

 

Given the array A = [1,1,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,0], then

 

Aones = [2,1,6,4,3]

Azeros= [1,2,4,1,5]

 

So, Aones and Azeros hold the counts of each set of consecutive ones and zeros respectively.

 

I did an algorithm that uses loops and case structure to find the counts of consecutive ones sets and store them in Aones. Then run the algorithm again for zeros and store them in Azeros. The data sets I'm working on are huge! So, I'm lookign for the best solution (fastest algorithm) for above case.

 

Any help?

 

Thanks

WB

 

0 Kudos
Message 1 of 38
(3,884 Views)

Why don't you start the ball rolling by posting your existing code.  If this is a homework problem, you really need to put some effort into it ...  Besides, it will prevent us from simply recreating your solution (and will give us a benchmark to which to compare our "fast" algorithms).

 

Bob Schor

0 Kudos
Message 2 of 38
(3,873 Views)

This is a part of research project. Not a homework!! The way my algorithm is running is explained. If you have another way to do it please let me hear it and I take care of the performance analysis.

0 Kudos
Message 3 of 38
(3,866 Views)

I did an algorithm that uses loops and case structure to find the counts of consecutive ones sets and store them in Aones. Then run the algorithm again for zeros and store them in Azeros. The data sets I'm working on are huge! So, I'm lookign for the best solution (fastest algorithm) for above case.

 


 


"I did an algorithm that uses loops and case structure" is not exactly a specific description of what you are doing.  Posting the code is the best way for us to see exactly what you did and exactly how it can be improved.

0 Kudos
Message 4 of 38
(3,859 Views)

 

I would initialize 2 arrays half size (worst case scenario, depends on your cluster sizes) with ones (or typical cluster size) and for looped the original array, replacing current element in the end of the cluster. Then cut away the not used portion.

Minimum change of array size, initializing with ones even does not update values, just shifts counter. only one big loop.

 

PS: cluster - portion of consecutive ones or zeros

0 Kudos
Message 5 of 38
(3,848 Views)

Thanks Alex-- How many case structures would you need inside the big loop?

0 Kudos
Message 6 of 38
(3,836 Views)

1.JPG

2.JPG

0 Kudos
Message 7 of 38
(3,827 Views)

Conditional Tunnels makes life a little easier...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 38
(3,804 Views)

Thanks 

0 Kudos
Message 9 of 38
(3,794 Views)

I think this might be the fastest solution. Unfortunately shift registers won't let you do parallelization, but I think that's the only way.

ZerosAndOnes.png

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 10 of 38
(3,790 Views)