LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search Array and Sort Array

This VI currently calculates each student's grade and class average based on the exam scores and their weighted percentages. How would I go about ranking each student based on their class average? Would you search the array for the average then sort it? The rank has to correspond to the number of students from the input so starting at 1 and ending with the amount of students in the class. 

0 Kudos
Message 1 of 8
(3,358 Views)

Did you run into a case where you had negative scores?  If so, do you REALLY want to make the positive using the absolute value there?

 

Hit Ctrl+Space and search for sort array. 

0 Kudos
Message 2 of 8
(3,341 Views)

I don't think there will be any negative scores because the lowest is a 0. That function is a round to infinity which ensures that any course average that comes out as a decimal will round up to the nearest integer.

0 Kudos
Message 3 of 8
(3,330 Views)

The Sort 1D Array works on clusters.  It uses the order of the cluster to determine what to look at first.  So if you build the cluster with the exam score first, then you can just use the Sort 1D Array.

 

And from your example, there is no need for the Build Array and the Index Array.  Those are just canceling each other out and adding nothing but confusion.

 

You also might want to move the Round To +Inf to be before the case structure in the data flow.  You could run into a weird corner case where the grade will not match the score.  Imagine a score of 89.1.  The case structure will round it to 89 and give a B while the score will be a 90, which should be an A.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 8
(3,320 Views)

Sort Array works on arrays of cluster, but order according to the 1st element. In this case it'd be easy to set the average as 1st element and then sort.

Also, Build Array followed by Index array does ZILTCH! Remove both.

You have a bug/error waiting to happen. You use Round to infinity, but wire the unrounded value to the case, which will perform normal rounding, so if e.g. someone has 89.2 average score, they'll get a B grade, but have 90 as listed score.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 8
(3,292 Views)

Thank you for the help. I've deleted the build array and index array and moved the round to infinity to before the case structure. However, connecting the sort array function to the output cluster of the bundle function gives an error. Would I have to build an array first and then connect it to the sort array? Or use the cluster to array function? Neither seem to be working.  Thanks again.

0 Kudos
Message 6 of 8
(3,275 Views)

@jlc98 wrote:

Would I have to build an array first and then connect it to the sort array?


Yes, you have to build the array first.  So put the Sort 1D Array to be AFTER your FOR loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 8
(3,267 Views)

@Yamaeda wrote:

Sort Array works on arrays of cluster, but order according to the 1st element.


Just to expand on this, it actually sorts by all cluster elements, using the cluster order as precedence. (i.e If several array elements have the same value for cluster element 1, it would sort these by cluster element 2, and so on).

0 Kudos
Message 8 of 8
(3,260 Views)