07-26-2017 02:18 PM - edited 07-26-2017 02:20 PM
Hello,
I am attempting to search for specific headers in an array. If they are found, I wanted to then delete all the COLUMNS with that specific header. Can you help me accomplish this?
Thanks,
hiNi.
Solved! Go to Solution.
07-26-2017 02:27 PM
Use "Delete From Array" and wire the index into the column terminal:
07-26-2017 02:29 PM
Sorry, snippets not working.
07-26-2017 02:45 PM
I do not think this will work. As you delete columns the index will change, so you will be deleting the wrong column. A small modification should make it work.
There is probably a better way to do this, maybe like this
I need to head to a talk so I cannot test thoroughly, please verify that it works for you.
Cheers,
mcduff
07-26-2017 02:53 PM
Just found a problem, need a sort array in the second method, like below.
07-26-2017 03:20 PM
Lol, sorry, I only tested it for one column... Yeah the index will change so, actually, I think you need to sort the array of indices, then reverse it.
I don't think that second method works because you are building up the array as rows instead of columns with the auto-indexing.
07-26-2017 03:38 PM - edited 07-26-2017 03:45 PM
Hello Mcduff,
Your solution does not work.
07-26-2017 04:32 PM - edited 07-26-2017 04:39 PM
Using "delete from array" in a tight loop is cringeworthy and not efficient. For each deleted row, tons of elements need to be reshuffled in memory (note that 2D arrays are stored linearly in memory order, and must be contiguous, so each deletion of a row requires moving most array elements to a new location. In the end most elements have been moved numerous (numerous!!) times!)
(See also our NI-Week 2016 presentation)
Sometimes it is easier to swap the search and look for the rows to keep. Now we can build a new array with those and simply transpose later. I am sure that's still much more efficient. Here's what I had in mind.
07-26-2017 04:59 PM
@HopeH wrote:
Sorry, snippets not working.
They work if you expand the image and click the download button. You'll have to go find where it was saved (download folder).
07-26-2017 05:08 PM - edited 07-26-2017 05:08 PM
So, back to the original code. There is no need for a multiframe state machine and tons of shift registers, controls that are never used (=data in), etc.
Here's how it could look like.