01-27-2017 08:46 PM
Hello all.
Maybe this issue has been addressed already, however, searching he forums has proved to be fruitless. Here is the problem: I have a 1-d or 2-d array of, to put it simply, a massive amount of of "whole numbers". I want to input all of these numbers into an array and then find and display the repeats. ie. if 13, 26, 59, 35, and 28 repeat more than once, i need to show those numbers in an indicator array for fast and "easy" reference. Obviously search array will come into play along with array size and index, a for loop the iterates N times, etc., however I am having an issue with the "placement" of said functions and display. can anyone help?
01-27-2017 09:28 PM - edited 01-27-2017 09:29 PM
Here is one way. Use a FOR loop with autoindexing and use Search 1D Array to see if the current element is repeated. The search should start from the next element (i+1). If there is a repeat, check to see if you don't already have that item in the list. If not, Build Array. Store the repeated llist in a shift register.
01-28-2017 10:57 AM
01-28-2017 11:57 AM - edited 01-28-2017 12:18 PM
Are all numbers relatively small positive integers (e.g. less than a few million)? In this case easiest would be to construct a histogram array (index=value of integer, value=count) and then pick all indices with values >1. (top code)
In the more general case where the range can be infinite, I would use a variant attribute based approach (bottom code).
Both are efficient and don't require searching through the entire array over and over again. Some of the earlier solution might scale poorly with array size. (Please benchmark to verify. The above posters are excellent programmers). It also probably depends if very few or most elements are repeated in the input.
If you have a 2D array, simply reshape it to a 1D array with a size corresponding to the product of the dimensions and apply the same code. (Or just use a double-stack of FOR loops).
01-28-2017 12:00 PM
Ben64,
Attempting to do what you have suggested, this is what I have come up with. Not sure if i did anything wrong but it seems to not work quite right. also would it be possible to use a 2-d array? pardon the silly questions but I havent been programming for 2 years and some of the simple stuff escapes me.
01-28-2017 12:10 PM
You should have said that you are using LabVIEW 2012. We can easily downconvert and attach the code if needed. The above images are all snippets that can be dragged to an empty diagram and will magically turn into executable code if you have LabVIEW version that can read them. The version of the snippet is shown in the upper right).
Here is my code saved in LabVIEW 2012.
01-28-2017 12:23 PM
My bad. Sometimes I don't think about these things.😜
01-28-2017 12:51 PM
@Myke wrote:
Not sure if i did anything wrong but it seems to not work quite right.
One glaring mistake is the fact that your conditional output tunnel does not do anything useful. Compare the code pictures!