05-28-2015 08:51 PM
Hi LV warrior.
I have a problem concerning manipulating data of an array.
I have an array of elements(numbers), and I want to count the different elements in an array.
Example : Array of (1,1,1,1,2,2,2,3,3,3,3,3,5,5,5)
I want to have at the end a listbox showing that we have :
4 Times 1
3 Times 2
5 Times 3
3 Times 5
I have no idea how. Any insight would be helpful..
Thanks
Solved! Go to Solution.
05-28-2015 08:53 PM
@syahid89 wrote:
Hi LV warrior.
I have a problem concerning manipulating data of an array.
I have an array of elements(numbers), and I want to count the different elements in an array.
Example : Array of (1,1,1,1,2,2,2,3,3,3,3,3,5,5,5)
I want to have at the end a listbox showing that we have :
4 Times 1
3 Times 2
5 Times 3
3 Times 5
I have no idea how. Any insight would be helpful..
Thanks
Start learning how to program in LabVIEW.
05-28-2015 09:03 PM
Hei thanks for the response (I Guess)
My Idea is to split the array containing different element, then calculate size of every newly formed array.
But I do think this idea is not effective, and there must be easier way to do this.
05-28-2015 09:54 PM - edited 05-28-2015 09:55 PM
You can use variant attributes. Take a look at this thread 'How to find the mode of an array of strings'.
You just need to convert the numbers in your array to strings because the variant attributes are strings.
05-28-2015 10:10 PM
Suppose I gave you a list of numbers --- 2, 2, 2, 5, 5, 5, 5, 7, 7 -- and I asked you how many of which numbers there are (but I didn't tell you the answer). Could you tell me? Asssuming that the answer is "Yes", how did you work it out? What steps did you use? Can you write down the steps? [This is called an algorithm].
Once you have the steps written down (in your native language), can you see how to do any part of any of the steps using LabVIEW?
Leave the last part of your problem (displaying the answer in a listbox) for last -- figure out the algorithm first. It is basically a counting problem ...
Bob Schor
05-29-2015 04:32 AM
Here's a sample of two ways that were mentioned before. Try to get the most of them, and maby find a better solution?
05-29-2015 06:20 AM
This problem would be a nice candidate for a Code Miniature. Building an array in a loop disqualifies my solution if you might end up with large arrays.
05-29-2015 08:47 AM
Another way using OpenG functions 🙂
05-29-2015 08:50 AM - edited 05-29-2015 08:50 AM
@sandal wrote:
Another way using OpenG functions 🙂
That's the way I was thinking. It won't be the most efficient, but it is usually good enough, and besides everyone already has OpenG installed anyway right....right guys?
Also the OpenG version has polymorphic support for various data types.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
05-29-2015 08:25 PM
Here is a version which generates a 2D array as output. The first column has the counts and the second column has values. It sorts the input array so there is no restriction on the order of the elements in the input array. Limitation: Integer data types.
The second case structure handles the two cases where the last two elements in the sorted array are the same or different.
Credit to Bob Schor: After thinking about the issue for a bit I wrote down the algorithm before I started coding. The algorithm is not spelled out in the VI.
Lynn