LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I count duplicate elements in a 1D Array?

Solved!
Go to solution

Hi everyone, I am trying to count how many numbers are duplicated in a 1D array. I just want to count different numbers. For example, I have this array:

 

1

2

1

3

1

2

4

 

The counter should be 2, because only the number one and two are duplicated, it does not matter how many times these numbers are duplicated.

 

Any help please?

 

PD: Sorry for my English, I speak spanish.

0 Kudos
Message 1 of 9
(7,849 Views)

What have you tried? Start with sorting the array!

 

Are all numbers small posiive integers?

0 Kudos
Message 2 of 9
(7,839 Views)
Solution
Accepted by topic author TWRLK

Hiiii

 

This will works

 

 

Message 3 of 9
(7,821 Views)

Attached is a simplified version that uses OpenG.  Probably not as efficient, but easier to code, and easier to understand.

0 Kudos
Message 4 of 9
(7,759 Views)

Hi TWRLK!

 

Just as an FYI, NI has spanish speaking engineers (Like me!) so you can also post in spanish and get an answer from us. The code provided by karthickkece seems to do the trick :D! However, your chances of getting an answer from the community are way higher if you post your question in english as you did here. 

 

Spanish version:

¡Hola! solo por si no sabias, NI también tiene ingenieros que hablan español (¡Como yo!) así que si formulas tu pregunta en español también puedes recibir asistencia de nuestra parte. El código que karthickkece parece hacer lo que vos describes. Igualmente, la mayoría de nuestros usuarios hablan ingles, por lo que es mucho más probable que puedas recibir colaboración de personas en la comunidad si creas tu post en inglés. 

 

WenR

0 Kudos
Message 5 of 9
(7,733 Views)

Than you very much. That is exactly what I needed.!!

 

0 Kudos
Message 6 of 9
(7,720 Views)

Hi TWRLK,

 

Could I do in this way? Since I'm a little lazy to write the for loop.....

 

 

20150911001.png

0 Kudos
Message 7 of 9
(7,708 Views)

William1225 wrote:

Could I do in this way? Since I'm a little lazy to write the for loop.....


Not if fractional values are allowed.

Message 8 of 9
(7,692 Views)

If the input array only contains "relatively small" (i.e. <1e6) non-negative integers, here's a very efficient way to do all this.

 

 

 

 

Download All
0 Kudos
Message 9 of 9
(7,639 Views)