LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Replace series of 0s with one 0

Hi. I have big chunk of 1 and 0 . I would like to replace a 0 for every greater than 5 number 0s , the same for 1s

like this.

if this is my input data:  000000111111110000001111111000   I would like to change it to 0101000  

Could you please help me on this one and show me with a sample code How I can do it in LabVIEW. Many thanks

 

 

 

0 Kudos
Message 1 of 25
(2,732 Views)

binarydataregex.png

Message 2 of 25
(2,723 Views)

could you please attach the vi, also is ther any way to delete the 0s in the end ( because number of 0s is less than 5 )

 

so 11111100000111111000 should be changed to 101

Many thanks

0 Kudos
Message 3 of 25
(2,719 Views)

Here's a non-regex solution. 😄

 

 

Not fully tested. Please verify correct operation.

 

 

Download All
0 Kudos
Message 4 of 25
(2,707 Views)

@altenbach wrote:

Here's a non-regex solution. 😄 

 


Any advantages over the regex from Darin? Is it something to do with memory/speed/performance?  Just curious.

0 Kudos
Message 5 of 25
(2,697 Views)

You should benchmark it. Are the strings big enough that it actually matters?

0 Kudos
Message 6 of 25
(2,693 Views)

@altenbach wrote:

Are the strings big enough that it actually matters?


Actually I wouldn't know. This is something only "tintin_99" would know. But I just saw Darin's example and looks simpler (code wise) than yours. So I'm thinking if regex has any shortfalls (in this case) compared with non-regex version. 

 

Kas

0 Kudos
Message 7 of 25
(2,687 Views)

@tintin_99 wrote:

could you please attach the vi, also is ther any way to delete the 0s in the end ( because number of 0s is less than 5 )

 

so 11111100000111111000 should be changed to 101


This is in direct contradiction of your first message, where the trailing tail was retained.

 

If you want this functionality, you can modify my last case structure on the right and delete the "initialize array" and make the output tunnel to "use default if unwired".

0 Kudos
Message 8 of 25
(2,682 Views)

Many thanks 

0 Kudos
Message 9 of 25
(2,679 Views)

@tintin_99 wrote:

Many thanks 


Yes, just modify the innermost case structure. for example you could make folliwng cases:

 

  • [4..] Same as current case
  • [default] output empty array.

etc...

0 Kudos
Message 10 of 25
(2,674 Views)