LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (10/19/2009) - Delete From Array

Another one of those functions that has me convinced that I should be reading the release notes that come with each new LV version, "Delete From Array".  I used the functionality for a long time, and missed when NI slipped it into the array palette.  We have all probably built an array using a while loop to pick off elements based on some condition, like numbers in a string.  Inevitably, the last element is empty/zero or otherwise unwanted.  Before this function came along, it took a fairly simple, yet repetitive series of functions to pick off the last element.  Now, just drop it in and its default behavior does this exact thing for you.  A less frequent, yet more complex task is to remove an entire row or column from an array.  It can still be a complex task, but at least the work is done under the hood, so while it may not always be fast, hopefully it is more efficient that writing your subVI.

 

The screenshot shows an example of deleting rows and columns.

VIOTD Delete Array.png

 

You could also transpose/delete/transpose to get rid of the last column, I am just pointing out that sometimes I wish you switch the default disabled index and still get the last column.  Finally, in principle, I suppose that this should be fairly memory neutral since the array gets smaller, but I seem to find that LV is pretty conservative when it comes to buffer allocations using this function.  Therefore, I think the same caveats apply here as to Insert into Array, namely try to avoid using this to delete rows/columns when you have control over the data creation.  Sometimes you have existing data you need to modify, and then this function can be really useful.

 

VIOTD groundrules here.

Message 1 of 6
(3,487 Views)

Tossing the last element is probably what I use this for most often. A close second is when I have to prime a shift register like when I am calculating the change sample to sample, the deleted element is used to init a shift register and the rest of teh array feeds the for loop.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 2 of 6
(3,473 Views)

I use Delete from Array frequently with arrays of VI Server references.  It's handy for gaining access to the single reference that I want, and closing all the rest:

 

dfa_refnum_array.png

Message 3 of 6
(3,464 Views)

Here is something silly that bit me in the butt recently:

 

 

facepalm.png

 

When I saw my error here, it was a pretty dramatic *facepalm* moment.

 

-nickerbocker

Message 4 of 6
(3,422 Views)

Nickerbocker,

 

For future reference, if you have a sorted array of indices of items to delete, it will work if you reverse the array of indices, along with the array.  Index-based deletion from the end works way better than from the beginning... 😉

Message 5 of 6
(3,418 Views)
Good idea, Darren.  I can't remember how I ended up solving it (friggen code is on an ext. hard drive that I left at home today, makes for a good Monday...*facepalm* lol).  I will keep that in mind.
0 Kudos
Message 6 of 6
(3,413 Views)