LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sort many array

I have many 1D array of random size, the elements random:

Array#1 [8 85 42 62 54 12 64 232]       Value max in array: 232

Array#2 [21 31 40 35 43 12]                 Value max in array: 43

Array#3 [8 6 42 13 45 54 21 64 23]      Value max in array: 64
.
.
.
Array#n [n n n n n n n n]                         Value max in array:n


I want to be able to sort the many arrays in ascending order of " value max in array" , the results would be:

 

Array#2 [21 31 40 35 43 12]
Array#3 [8 6 42 13 45 54 21 64 23]
Array#1 [8 85 42 62 54 12 64 232]
.
.
Array#n [n n n n n n n n]

How to do this in LV?

0 Kudos
Message 1 of 3
(1,864 Views)

Which version of LabVIEW? There may be some additional benefits using Maps in 2019. Actually, you could use a Map, but it doesn't seem really necessary here...

 

For arrays of different lengths you'll want to use Clusters.

You can combine the array, the max value of the array (use Array Max and Min) and the index of the array (array #1, #2 etc) together. If you make the Max value the first element in the cluster and the array number the 2nd element, then build an array of these clusters, the Sort 1D Array node will give you what you want.

Example_VI.png

This example uses the Random Number (Range) VI which ships with 2019, but is otherwise available in earlier versions.


GCentral
Message 2 of 3
(1,843 Views)

@vuka wrote:

How to do this in LV?


You would do it similar like in any other programming language. 🙂

 

Here's something to start with...

 

SortByMax.png

Message 3 of 3
(1,837 Views)