LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting a array into classes

Solved!
Go to solution

Hello everybody,

i have a tricky (hopefully just for me! Smiley Wink) problem. I want to sort a 1d array of values into size-classes. First I wrote a code-monster without a loop. Works fine but to increase the number of size classes is really awful. Now I want to make the code more flexible. Just give a 1d array of size-class limits like [0,1,2,4,8..] and the raw data to the vi. As result I want a x-d Array like in the picture below.

I wrote a code for that but after many hours of work it doesn’t run. Could anyone look to the code sample in the file and give me a hint?

 

Thank you in advance!

 

Paul

 

PS: In the following picture want to show how it should work in the end.

 

 

example.PNG

 

 

0 Kudos
Message 1 of 5
(2,745 Views)

Hi Meisspa,

 

please see vi attached, maybe it wil give you an idea.

Duri
0 Kudos
Message 2 of 5
(2,729 Views)

Something is wrong with the way you are building the array of found day and then inserting it into the 2-D array.  Rather than inserting into an array, you should probably be doing a Replace Array Subset after pre-initializing the array.  Rethink you logic as to how you are putting new data into the array.

 

Some tips.

 

Use In Range and Coerce to determine if a number is within range.  One function instead of 5.

 

Index Array is resizeable, so instead of splitting the array wire and using 2 index array functions, you can expand index array.  Wire an value into the first index input, the one below it will automatically give you the element at the following index as well.

 

For Loop as a conditional stop terminal (not visible by default).  This will let you stop the loop as soon as the element is found to be in range.  You shouldn't need to use the conditional tunnels in that situation.

0 Kudos
Message 3 of 5
(2,724 Views)
Solution
Accepted by topic author Meisspa

Not too hard at all

!1-1.png

A few sorts and threshhold array works wonders


"Should be" isn't "Is" -Jay
Message 4 of 5
(2,720 Views)

Hello,

 

thank you very much for the given hints and codes. I used in the end a mixture of the code sample from Duri and the hints from RavensFan because it helped me to solve different problems at once. The source from Jeff is really elegant too!

 

Thank you! 

 

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