LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

arrange array in ascending order

I need to display n random numbers in an array and then in a second array display the same random numbers in ascending order. n is a user input.

 

I have the random number in a for loop and the array outside the for loop. Now i dont know how to put those numbers in another array in ascending order.

 

Thanks

0 Kudos
Message 1 of 9
(10,829 Views)

I would use the Sort 1D Array Function.

http://zone.ni.com/reference/en-XX/help/371361H-01/glang/sort_1d_array/

And then if you also wanted them in the reverse order you could use the Reverse 1D array Function.

http://zone.ni.com/reference/en-XX/help/371361H-01/glang/reverse_1d_array/

 

0 Kudos
Message 2 of 9
(10,827 Views)

Have you worked through the on-line tutorials fro LabVIEW.  They are a good way to get started.

 

Lynn

0 Kudos
Message 3 of 9
(10,818 Views)

This is your solution....

 

Not sure what version LV you have, but i saved it to an OLLLD version. 

Download All
Message 4 of 9
(10,812 Views)

@Fernando0901 wrote:

This is your solution....

 

Not sure what version LV you have, but i saved it to an OLLLD version. 


 

You are kidding, right? All you need is branch the array of random numbers and apply the "sort array" function.
0 Kudos
Message 5 of 9
(10,805 Views)
I know, but I'm thinking if he needs to expand his data set with additional data types, he has the capability to sort it.
0 Kudos
Message 6 of 9
(10,800 Views)

I don't understand. Why would other datatypes be any different?

0 Kudos
Message 7 of 9
(10,787 Views)
I never said the sort array was wrong. From my experience, an array of doubles may need to be expanded into an array of clusters containing a dbl, string, arrays of either dbl/string, and maybe a timestamp to define a data set. I figured including the ability to allow for expandability was something worth doing. 😞
0 Kudos
Message 8 of 9
(10,772 Views)

Well, you only said "this is your solution", without explaining anything. Your overly complicated code is not needed to answer the very specific question in the first post. It only confuses and introduces extra advanced concepts (e.g. the fact that cluster are sorted according to the cluster order, the way to name the elements of a cluster when using a plain bundle so we can later unbundle by name, your example does not contain "N" as required, etc.).

 

(If somebody asks how to change a light bulb, you don't explain how to rebuild a transmission. :D)

 

Here is the full solution:

 

0 Kudos
Message 9 of 9
(10,766 Views)