LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Number of repeated numbers in an array

Hello everyone,

I've got a question that I haven't been able to figure out. I have an array containing 6 numbers, and this figure will remain fixed, it won't change.

 

brianalejandro15_0-1714621398300.png

 

As you can see in the attached image, I need it to tell me how many numbers fall within different ranges. For example:

1D Array

Data #1: 202602

Data #2: 87410

Data #3: 94178

Data #4: 42647

Data #5: 202500

Data #6: 338100

 

Through indicators, it should output this:

Range #1 (201000 - 203000): 2

Range #2 (85000 - 90000): 1

Range #3 (93000 - 97000): 1

Range #4 (40000 - 45000): 1

Range #5 (335000 - 340000): 1

 

I would greatly appreciate your help with this. Thanks a bunch!

0 Kudos
Message 1 of 5
(602 Views)

Hi Brian,

 


@brian.alejandro15 wrote:

I would greatly appreciate your help with this. Thanks a bunch!


  • You need an input for the ranges.
  • You should use a loop to process each value of your input data.
  • Inside the loop you need to detect the range of each element of your input data.

What have you tried and where are you stuck?

(We don't do homework for free, but will help with specific problems and code improvement.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(578 Views)

@GerdW wrote:

 

(We don't do homework for free, but will help with specific problems and code improvement.)


We also don't do homework "for pay", which is why we often hide behind anonymous "avatars" on the Forum.

 

Bob Schor

0 Kudos
Message 3 of 5
(536 Views)

The first step solving a problem is defining it fully. Your image and description are insufficient for that.

 

  • What is the datatype of your numbers (DBL? I32?, etc.)
  • The term "within" is vague. Are the boundaries included or excluded?
  • Are we just ignoring any value that is not within one of the ranges or do we want to count those too? (Of course we can also deduce that if the sum of results is less than the size of the input array).
  • What "figure" remains fixed? the element values? The array size? Something else? (A proper solution should be scalable and not depend on any assumption about size, for example)

What have you tried and what is your remaining problem?

 

  • reading the input?
  • defining the ranges?
  • checking the ranges?
  • formatting the result?
  • something else?

Attach your VI (containing typical default data for all controls) and show us what you tried. Chances are that we can point you in the right direction. The solution will probably fit on a postage stamp.

 

0 Kudos
Message 4 of 5
(474 Views)

As an excellent learning exercise, try to implement the following code from scratch then try to fully understand every detail, how it works, and the purpose of every single code element. (Your teacher reads these forums too and will recognize plagiarism!). While it only took me a few minutes to make, it might take you half a day, but you'll learn a lot!

 

Note that there are a few landmines, so make sure to fully understand the various types of tunnels, the meaning of the diamonds on the range check icon, potentially invisible characters in the format string, the use of a fixed-width font for the indicator, and other subtleties. 

 

This will work for any input array size (up to ~2^15) and will even work correctly if the ranges overlap and input numbers can fall in more than one range. If the input array can have more than ~2^15 elements, some datatypes need to change, but which ones and how?? It will work equally well if there are fewer or more different range columns in the 2D array diagram constant. Scalability!

 

altenbach_0-1714933845293.png

 

 

 

0 Kudos
Message 5 of 5
(464 Views)