![]() |
LabVIEW - Need help with Arrays
In LabVIEW, let's say I have two 1D arrays, let's call them A and B, in which A is longer than B, and all of B's elements are equal to some elements of A. I would like to reconstuct A into a shorter array, removing the elements that equal to an element of B.
I've done this in MatLab using the ismember and nonzeros functions, but I'm not sure how to do it in LabVIEW. How might I go about this? |
Re: LabVIEW - Need help with Arrays
1 Attachment(s)
If you want a quick and dirty diagram, then I'd build it as...
ForEach element in B, Search for and optionally delete the element in A. See the image below. The ForEach in LV is simply a For loop with the array wired as an input and with auto-indexing left on for the tunnel. The default is to have [] on the tunnel, and that indicates that the array will be auto-indexed. The Search can be done with the Search 1D Array, the icon with the looking glass, probably third row, second column. Delete uses Delete from Array. A key element you'll need is that A needs to be wired to and through a shift register on the For loop. The shift register is the best way for one iteration of a loop to feed data to the next. If you use a regular tunnel, the original array on the wire will enter the loop each iteration. NOTE: You may be tempted to make a control and read/modify/write to it each time through the loop instead of using the shift register. While this will work in simple programs, it opens you up to race conditions as the diagram grows, and it is slower because the UI is updated for each write, and each access now needs to be protected -- again due to potential parallelism. Since shift registers have a limited scope, they avoid race conditions and performance implications. It is an important element of the LV language, so don't fall to the temptation. The contents of the loop will be a search for the element of B, with the output index wired to the index on the array delete. Then wire the output array to the right shift register. If the search fails, it will return -1 for the index, and a delete of -1 is a no op on the array. This diagram may need to be modified if you want to search and delete every instance of the B element. And of course if this needs to be optimized for big arrays, you can improve it with some sorts and by using the search from input and by avoiding the numerous resizes by using replace with a nonsense value instead of deleting and resizing the array each time. Greg McKaskle |
Re: LabVIEW - Need help with Arrays
This looks really great. Thanks for the help. Just before you posted, I was able to come up with something that works. I did it a very similar way, but I used an Index Array function to send each value of B, into the "element" part of the Array Search. And I did the way you said not too, and I didn't use shift registers. I'll definitely have to read up on shift registers, and try your way. Thanks!
|
| All times are GMT -5. The time now is 10:36. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi