LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Truly deleting rows from 2D array?

Solved!
Go to solution

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?

0 Kudos
Message 1 of 6
(5,581 Views)
Solution
Accepted by murchak

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.

Message 2 of 6
(5,578 Views)

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

Antoine Chalons

Message 3 of 6
(5,571 Views)

Thank you Ravens and TiTou.

 

I will try your suggestions and see what I'll get.

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

@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

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 6
(5,558 Views)

This is exactly what I'm looking for. Thanks you all. The picture below should be what you meant.

delete rows with indices in 2D array.JPG

0 Kudos
Message 6 of 6
(5,440 Views)