LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Counting the amount of like elements in an array

Hi,
I am very new to labview and would be grateful if anyone could help with the following.
I have an array of data and each element contains one of the integer values 0,1,2 or 3.
I want to be able to count the number of times each of these occur. ie 3 occurs 10 times etc.
This is probably a really simple problem but I cannot figure it out and would appreciate any help.
Thanks,
Maria
0 Kudos
Message 1 of 11
(3,381 Views)
Hi Marialre
 
Look at this function (Built in LabVIEW 8.0). Maybe you can use it. Otherwise, you can modify it for your application
 
Best regards,
Nick_CH
0 Kudos
Message 2 of 11
(3,370 Views)
A built-in histogram function would also do this counting for you. Just set up the bins it looks for to be 0-1, 1-2, and 2-3. This is an easy and flexible solution. The downside is that the histogram operates on floating point numbers, so you induce a bit of rounding into your equation. If you're just checking for 0,1,2, or 3, you should be safe.

Search the functions palette for histogram or search the Example Finder.
Jarrod S.
National Instruments
Message 3 of 11
(3,358 Views)
Hi Guys,
Thanks so much for getting back to me so quick. I am using labview version 7.1 so I cannot open the count VI that you posted. Is there any other counting VI that I can use with the version that I am working with??
Thanks again,
Maria

0 Kudos
Message 4 of 11
(3,332 Views)
you can use the equals to compare an array of elements to a single element value, you will get an array of booleans.  Convert this boolean array to 0,1 (Ture will be 1) and sum the array.  The nice thing is that equals is polymorphic so if you change types your code should (for many data types) not break.
 
 
Paul
Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 5 of 11
(3,326 Views)

Here is a quick 7.1 example, took about 30 sesconds to code up.

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 6 of 11
(3,323 Views)
Hi Marialre,

I save my VI for a previous version. Now you can use it with the version 7.1 of LabVIEW.

Best regards
Nick_CH
0 Kudos
Message 7 of 11
(3,323 Views)
Thanks so much for all your help guys. It would have taken me weeks to figure something out.
It's all good now.
Thanks again,
MariaSmiley Very Happy
0 Kudos
Message 8 of 11
(3,308 Views)
Here's what I would do. 😄
 

Message Edited by altenbach on 03-02-2007 07:44 AM

Message 9 of 11
(3,297 Views)
Here's a more detailed version containing function labels so you cna recognize them better. It should be easy to built.
 
 
This is basicallly a general integer histogram function and can easily be adapted for larger (and smaller) selections (e.g. if the possible numbers are 0..999 you would initialize an array with 1000 elements of zero and everything else would stay the same.
If the possibilities are e.g. -5..5, you would use an array size of 11 and add 5 to each element.
 
All clear? 😄
 
(Nick's solution would need to be rewritten whenever the number of tests changes and would be unmanagable for dealing with 1000 elements 🐵

Message Edited by altenbach on 03-02-2007 08:03 AM

Message 10 of 11
(3,290 Views)