LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DELETE ARRAY ELEMENT

Hi

 

 

I want to delete every 4th element in an 1D array.

I am attaching my vi.

I understand I am not getting my expected result since I am keeping my FALSE case unwired...but I am not getting any workaround.

 

Plz help

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

Hi ni4me,

 

you need to learn several things:

- usage of shift registers (to keep values from one iteration of a loop to the next iteration)

- wiring the FALSE case of a case structure - instead of "use default value if unwired"!

 

When you have taken those steps you will notice your deletion algorithm is flawed: after deletion of index 4 the remaining elements are changing their indices: element 5 becomes element4, 6 to 5, and so on. But you still keep on counting like everything is still in place…

Solution: Start deleting at the end of the array!

 

When your arrays will always have a size a multple of 4 you could try this instead:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 6
(4,172 Views)

A possible solution, the case structure have a default case and 0 case . on the defaul wire the array withouth nothing else, in the 0 case you add the element on the new array.

 

 

Nicola
LabVIEW DeveloperByteLABS.
0 Kudos
Message 3 of 6
(4,155 Views)

@ByteLABS wrote:

A possible solution, the case structure have a default case and 0 case . on the defaul wire the array withouth nothing else, in the 0 case you add the element on the new array.


Better yet: Conditional Indexing Tunnels!


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 4 of 6
(4,119 Views)

If this code runs often and the array is large, it may be more memory efficient to initialize an array first and copy the original array's elements (the ones that you want to keep) in the for loop.  Since you know how many elements you expect to keep, you only have to initialize your array once (whereas the conditional indexing tunnel has to re-allocate memory for the array each time you append a new element).

0 Kudos
Message 5 of 6
(4,110 Views)

@berkinorbi wrote:

If this code runs often and the array is large, it may be more memory efficient to initialize an array first and copy the original array's elements (the ones that you want to keep) in the for loop.  Since you know how many elements you expect to keep, you only have to initialize your array once (whereas the conditional indexing tunnel has to re-allocate memory for the array each time you append a new element).


The Conditional Indexing Tunnels in a FOR loop do exactly as you just described.


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
0 Kudos
Message 6 of 6
(4,075 Views)