LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Conditionally Delete Rows from 2D Array

Highlighted

Hey all,

 

I'm fairly new to Labview, and I would like to conditionally delete rows from a table consisting of multiple rows columns (basically a 2D array). I used the "replace array subset" function to 'remove' the unwanted rows, but it seems that I've lost the rest of the columns in the process.

 

Any hints as how to delete the unwanted rows while keeping all columns intact would be much appreciated.

0 Kudos
Message 1 of 8
(1,369 Views)

Use DELETE FROM ARRAY.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 8
(1,366 Views)

Hi Steve,

 

I'm not sure hot to wire the "Delete from array" exactly to get what I want. I want to delete all rows which do not contain "Tomato".

 

delete from array pic.PNG

The delete from array function needs the indexes of all the rows which need to be deleted. The only way I can think to get that is to use the "search 1D array" function and get the indexes of all the rows I don't want. But I can only search for one element. But instead I'd like to search for all other elements which do not equal the one I specify. 

0 Kudos
Message 3 of 8
(1,349 Views)

This is based on your initial vi. Please note the image is a snippet

delete.png


CLA CTA
Multics UK Ltd
Multics @ NI Week 2019: Learn about Architecting TestStand Framework for Noncoders Mon, May 20th, 3:15 PM - 4:15 PM. Room 19B
0 Kudos
Message 4 of 8
(1,321 Views)

@Zeustra wrote:

 

Any hints as how to delete the unwanted rows while keeping all columns intact would be much appreciated.


  • Your code seems to want to keep only rows with a certain pattern, not delete them (i.e. delete all the others).
  • You could use "search array", but then you need to use a while loop (because you don't know the number of iterations beforehand!) and keep the index in a shift register and search from the last found location in the next iteration. Stop the loop once no match is found. Still, "delete from array" should not be used in a tight loop, because it is relatively expensive. For example, with every delete operation, all higher rows need to be shifted down and at the end, the last elements would have been touched N times, while once would have been sufficient.
  • The overall patterns of your original code is fine, bot you should not slice out the first column if you want to keep the entire array. Place the entire array into the shift register, wire both indices to index array (one is zero for the first row and one in N for the row number) for comparison. Reshape the number of valid rows at the end.
  • You use LabVIEW 2014, so you have the conditional tunnel and the code by @.aCe. is pretty good. If the arrays are very large, you could avoid allocating that extra boolean array and keep most of the code inside the loop instead. For small arrays it does not matter.

 

 


LabVIEW Champion Do more with less code and in less time
Message 5 of 8
(1,313 Views)

@altenbach wrote:

@Zeustra wrote:

 

Any hints as how to delete the unwanted rows while keeping all columns intact would be much appreciated.

  • The overall patterns of your original code is fine, bot you should not slice out the first column if you want to keep the entire array. Place the entire array into the shift register, wire both indices to index array (one is zero for the first row and one in N for the row number) for comparison. Reshape the number of valid rows at the end.

1. Thank you altenbach. You've been very helpful so far. I didn't know about conditional looping, I learned that from you today Smiley Happy.

2. You're correct, I'm slicing off the first column and that's an issue for you. Could you please elaborate on the part of dealing with this issue? If I understand correctly, you're saying I should place 2 Index Array functions, one indexed at the first row and another at the Nth row? How do I wire them exactly?

 

shift register.PNG

 

I'm not sure where to go from there honestly.

 

Thank you in advance and sorry I'm quiet a beginner that's trying to self teach.

0 Kudos
Message 6 of 8
(1,275 Views)

Maybe like this?

 

There are plenty ways to do this, (I would stick with the simple earlier solution, of course)

 


LabVIEW Champion Do more with less code and in less time
0 Kudos
Message 7 of 8
(1,262 Views)

Excellent bit of code. Thanks for posting the final version! 

0 Kudos
Message 8 of 8
(861 Views)