From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Delete multiple elements from array

Hi everyone, my question is : how to delete multiple elements from 1D array (eg, element no.2, 4, 7) ? the number of deleted elements and the indexes are not constant

it seems Delete Element From Array function can only delete a consecutive elements. 

0 Kudos
Message 1 of 6
(13,274 Views)

Correct.

 

You need to do it in a loop and use the shift register to maintain the array between iterations.

 

Also be careful how you do it.  If you are deleting 2 , 4, and 7 and you go to delete 2 first,  then 4 and 7 now become 3 and 6.  Then you go and delete 3.  Now what was originally 7, and is now 6, will now become 5.  If you dont' account for that you'll have problems.

 

An easier way to delete from an array without having to worry about changing indices is to delete the later elements in the array first and move towards the front.

Message 2 of 6
(13,269 Views)

RavensFan wrote:

An easier way to delete from an array without having to worry about changing indices is to delete the later elements in the array first and move towards the front.


In other words, use Sort 1D Array and then Reverse Array on your array of indicies before going into the FOR loop.


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 3 of 6
(13,235 Views)

@crossrulz wrote:

RavensFan wrote:

An easier way to delete from an array without having to worry about changing indices is to delete the later elements in the array first and move towards the front.


In other words, use Sort 1D Array and then Reverse Array on your array of indicies before going into the FOR loop.


Like this.

______________________________________________________________


______________________________________________________________
Message 4 of 6
(13,226 Views)

I had a 2D array with more than 20000 rows and 38 columns. One column was meant as a filter criteria, i.e., I wanted to see only those rows where my filter column contains a certain value.

 

I found that using any operation that used shift registers in a loop too slow (be it by adding rows to a new, initialized array, or by removing rows from the original array), but using an array of clusters is (comparatively) fast.

 

So I use a boolean AND on the column containing the filter criteria with the value I wanted to filter for (giving me a True/False array that distinguishes between 'matches filter' and 'doesn't match filter'), plug the true/false together with the corresponding array row into individual cluster array elements, sort that cluster array (by true/false), split it, and resolve the cluster again. See attached vi.

Message 5 of 6
(12,625 Views)

Very good!

Thanks!


@ThisIsMyNickname wrote:

I had a 2D array with more than 20000 rows and 38 columns. One column was meant as a filter criteria, i.e., I wanted to see only those rows where my filter column contains a certain value.

 

I found that using any operation that used shift registers in a loop too slow (be it by adding rows to a new, initialized array, or by removing rows from the original array), but using an array of clusters is (comparatively) fast.

 

So I use a boolean AND on the column containing the filter criteria with the value I wanted to filter for (giving me a True/False array that distinguishes between 'matches filter' and 'doesn't match filter'), plug the true/false together with the corresponding array row into individual cluster array elements, sort that cluster array (by true/false), split it, and resolve the cluster again. See attached vi.


 

0 Kudos
Message 6 of 6
(6,453 Views)