05-14-2012 01:58 PM
I want to use the delete from array function to delete undesired rows from a 2D array.
Goal is to delete any row whose value for a given column does not meet some condition.
In my case, for a given row, if the value of column 1 is less than 2.5, I want to delete that row.
Typical answers on this forum suggest selecting rows that don't meet my condition, and building them into an array (working backward). What I want is to work with my 2D array, and delete rows that I don't want.
I know exactly why my VI will not work, but I don't know how to fix it. See the attached VI.
My VI will not work because the first time I delete a row from my original 2D array, and use the shift register in the for loop to pass the modified array to the next iteration, the index of the next row that I want
to delete pertains to the original 2D array, and not the modified array. How do I update the index to reflect the modified array?
Solved! Go to Solution.
05-14-2012 02:07 PM
Don't use the i terminal. Keep the index value in a shift register as well. If you delete something, just pass the current value through so you start at the same point (since the next row as now moved down to the current row.) If you don't delete the row, then add one to the index and pass it into the shift register.
That, or work in reverse. Start looking from the end of the array towards the beginning, so use the length of the array (N) minus the iteration terminal value then subtract one.
05-14-2012 02:14 PM
You just need to keep track of how many rows you've deleted.
Use a shift register for that, initialize it with 0 and each time you remove a row, add 1 to that counter.
The index of the row you want to remove is always i - counter.
Hope this helps
We have two ears and one mouth so that we can listen twice as much as we speak.
Epictetus
05-14-2012 02:22 PM
Thank you Ravens and TiTou.
I will try your suggestions and see what I'll get.
05-14-2012 02:47 PM
@Ravens Fan wrote:
Don't use the i terminal. Keep the index value in a shift register as well. If you delete something, just pass the current value through so you start at the same point (since the next row as now moved down to the current row.) If you don't delete the row, then add one to the index and pass it into the shift register.
That, or work in reverse. Start looking from the end of the array towards the beginning, so use the length of the array (N) minus the iteration terminal value then subtract one.
Working backwards is a nice elegent way to approach it because the array index are unchanged fore smaller index values so "you are only messing with indexes you don't have to worry about".
Ben
11-20-2012 01:21 AM
This is exactly what I'm looking for. Thanks you all. The picture below should be what you meant.