LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I delete a specific pattern from an array

Hi,

 

I have a question on what is the fastest- less memory way to remove a specific pattern in a 1D array

 

For example in 1D U8 Array I would like to delete ( and count the number) whenever I have 3 consecutive  0xFF 

 

For instance :   0xFF 0x2 0x3 0xFF 0xFF 0xFF 0x2 0x3 0xFF 0xFF 0xFF  becomes 0xFF 0x2 0x3 0x2 0x3   and I had this pattern 2 times in my array

 

Many thanks

 

 

 

 

0 Kudos
Message 1 of 6
(4,184 Views)

If you're considering only U8 arrays, I'd suggest the Search and Replace String option.

Example_VI.png

 

This link might also be useful: How to Convert Between Hexadecimal and ASCII in LabVIEW?


GCentral
0 Kudos
Message 2 of 6
(4,169 Views)

Question:  What happens if there are 4 or more in a row.

 

I'd just program it in a loop.  Search 1-D array for FF.  See if the next two elements are also FF.  If so, delete from array.  Search 1-D array from that point on for next FF.  Stop when you get to the end of the array.

0 Kudos
Message 3 of 6
(4,164 Views)

You will probably have to benchmark it but array operations may be faster that converting back and forth to strings.

 

remove pattern from array.png

Ben64

0 Kudos
Message 4 of 6
(4,125 Views)

@cbutcher wrote:

If you're considering only U8 arrays, I'd suggest the Search and Replace String option.

Example_VI.png

 

This link might also be useful: How to Convert Between Hexadecimal and ASCII in LabVIEW?


Let's make this a bit simpler:

replacer.png
And I'm quite sure this is much more efficient than Bens solution (Byte Array to String and String to Byte Array are basically no-op functions).

Message 5 of 6
(4,107 Views)

PiDi a écrit :


And I'm quite sure this is much more efficient than Bens solution (Byte Array to String and String to Byte Array are basically no-op functions).


Agree with you, about 4X faster.

 

Ben64

0 Kudos
Message 6 of 6
(4,100 Views)