LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to count repeated elements in 2d array

Solved!
Go to solution

Hi I need help. I need to count repeated elements in array. How to do that?

Please see attached file for sample output.

I hope someone will help me.

Thank you.

0 Kudos
Message 1 of 5
(3,019 Views)
Solution
Accepted by topic author maybel27

Search the forums, as this question as come up before.

 

Older solutions used variant attributes you search for and save the names as variants, if you find it , you add one to the property.  If you don't, you add the attribute and set its property to one.  At the end, you read out all that you have.  (I might have the exact terminology of the variants, attributes, and properties messed up, but when you find that thread, you'll see examples on how to implement.

 

Newer versions of LabVIEW have sets and maps that let you do something similar.

 

If you want, you can do it with straight arrays.  You have the array you are searching and the array you are building.  Search for each element in array 1 in array 2 (which starts out empty).  If you find the element, then add 1 to the same index in array 3 which is the count of instances for the elements in array 2..  If you don't, you Build the element to the end of the array 2 and build an element of value 1 to the end of array 3.

Message 2 of 5
(2,983 Views)
Solution
Accepted by topic author maybel27

You have a 1D array of names, not a 2D array.

 

A slightly harder problem is described here, bnt once the words are turned into array elements, it's the same.

 

Ravens correctly stated that now we should do it using a map. If you look at slides 36/37 of my 2019 NI week presentation, you'll get the idea. What is your LabVIEW version?

 

See  how far you get!

Message 3 of 5
(2,974 Views)

Thank you very much for your help 🙂 

0 Kudos
Message 4 of 5
(2,962 Views)

Thank you very much for you help 🙂

0 Kudos
Message 5 of 5
(2,961 Views)