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: 

Conditionally Delete Rows from 2D Array

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
(4,997 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
(4,994 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
(4,977 Views)

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

delete.png


CLA CTAChampionI'm attending the GLA Summit!
Subscribe to the Test Automation user group: UK Test Automation Group
0 Kudos
Message 4 of 8
(4,949 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.

 

 

Message 5 of 8
(4,941 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 :).

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
(4,903 Views)

Maybe like this?

 

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

 

0 Kudos
Message 7 of 8
(4,890 Views)

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

0 Kudos
Message 8 of 8
(4,489 Views)