LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

finding (not replacing) repeating integers

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?

 

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

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 8
(3,080 Views)

Here is another way using the Sort Array vi.

 

Find Repeats.png

Ben64

0 Kudos
Message 3 of 8
(3,031 Views)

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). 

 

Message 4 of 8
(3,017 Views)

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.

0 Kudos
Message 5 of 8
(3,014 Views)

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.

0 Kudos
Message 6 of 8
(3,010 Views)

My bad. Sometimes I don't think about these things.😜

0 Kudos
Message 7 of 8
(3,002 Views)

@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!

 

 

0 Kudos
Message 8 of 8
(2,993 Views)