02-23-2015 09:36 PM
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.
02-23-2015 09:40 PM
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.
02-24-2015 06:55 AM
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.
02-24-2015 07:13 AM
@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.
03-10-2016 04:49 AM - edited 03-10-2016 04:58 AM
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.
03-15-2019 04:25 PM
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.