LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array Value Counter

Solved!
Go to solution
Highlighted

I need help with what I hope is going to be a simple counter.

 

To make it simple, I have a large array, and I want to count how many times a range of numbers appear within that array and add it to the counter. (Or just count the total number of time it occurs). Hopefully the self-made example below will help.

 

Array                                  Values >= 50 (greater than or equal to)              Values >=70

10                                                6                                                                         3

20

30

40

50

60

65

70

75

80

Hopefully this makes sense. I am not sure how to go about this because I am fairly new to labview. Any tips or help is greatly appreciated. Thanks in advance

 

0 Kudos
Message 1 of 8
(796 Views)

Use a FOR loop to iterate through each item.  You can use shift registers to keeps your counts.  Do the comparisons inside of the loop and use a Select function to store the incremented count or the old count based on the comparisons.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 2 of 8
(785 Views)

Hi,

 

when the array is sorted you can use InterpolateArray to search for the index of the first element gt/equal than your limit. Subtract from array size.

When the array is not sorted: SortArray...

Best regards,
GerdW
CLAD expired, using 2009SP1 + LV2011SP1 + LV2017 (+LV2018 sometimes) on Win7+cRIO
Kudos are welcome Smiley Wink

Message 3 of 8
(775 Views)

Well, you need two counters, so an array with two elements is useful. Here's a simple draft:

 

CountEm.png


LabVIEW Champion Do more with less code and in less time
Message 4 of 8
(760 Views)

I appreciate all of the help. I ended up going with the array sorting feature and do a 1D lookup each time while comparing the index to the array size. All of the help greatly increases my understanding in the program and it is very helpful. Thank you all once again. I have attached a copy of my code just so you can reference and see how I went about doing it.

Quick background: The Numerics at the start of the code are incoming data points from a tester. Take the mean of those points and place them into an array and count how many times each point occurs (part that you guys helped me on). Hopefully this makes it understanding of what I am trying to do.

0 Kudos
Message 5 of 8
(731 Views)

ac.png

"If you weren't supposed to push it, it wouldn't be a button."
Message 6 of 8
(724 Views)

@Brschnei wrote:

I appreciate all of the help. I ended up going with the array sorting feature and do a 1D lookup each time while comparing the index to the array size. All of the help greatly increases my understanding in the program and it is very helpful. Thank you all once again. I have attached a copy of my code just so you can reference and see how I went about doing it.

 


First of all, sorting is O(NlogN) and each array element needs to be touched multiple times. In my code, each array element is only touched once for greatly improved performance, especially if the arrays get large.

 

Now let's look at your image (code) you attached above:

 

Tracking%20Screenshot

 

There are many things horribly wrong with this! All you need to do is keep a second shift register in the outer loop containing a I32 for each comparison, which each would get incremented according the the output or "mean" (similar to my code).

Specific problems:

  • each time you add an element to the array you start over sorting from scratch. The first acquired element will get processed N times. Once is enough! You sort ever-growing arrays from scratch, even though only one element has been added.
  • Your FOR loops make no sense. They operate on the same input and produce the same output X times according to some control as fast as the computer allows. What a waste! Once is enough! Remove the FOR loops!
  • Your controls and indicators don't belong inside the FOR loops. If the controls would change during the execution of the inner loops, you would get completely random results and since they are fixed, they should be diagram constants anyway.

LabVIEW Champion Do more with less code and in less time
Message 7 of 8
(714 Views)
Solution
Accepted by topic author Brschnei

Here's what I would do... (Just a code skeleton, so modify as needed, e.g. depending on where the data comes from, etc.)

 

CountLevels.png

 

 

(Now each mean is touched exactly once and never again!)

 

(And there is nothing wrong with this coercion dot ...)


LabVIEW Champion Do more with less code and in less time
Message 8 of 8
(709 Views)