05-17-2012 11:52 AM
I have two 1D array of same size, the elements are not in ascending/descending order:
Array#1 [3.5 5.1 4.2 6.2 5.4]
Array#2 [2.1 3.1 4.0 3.5 4.3]
I want to be able to sort the two arrays (in either ascending or descending order) base on one of the array, i.e if sort ascending based on Array#1, the results would be:
Array#1 [3.5 4.2 5.1 5.4 6.2] <-- this array is sorted (ascending order)
Array#2 [2.1 4.0 3.1 4.3 3.5] <-- this is not sorted, but the order is such that its elements still correspond to the same element in Array#1
..just like in Excel, you highlight two column, and click the "sort Ascending" button.
How to do this in LV?
Solved! Go to Solution.
05-17-2012 12:06 PM - edited 05-17-2012 12:09 PM
Combine your two arrays into an array of clusters where the first element of the cluster is from the first array, and the 2nd element from the second array. There is a function in the cluster palette called Index and Bundle Cluster Array that will do that for you.
Then sort the 1-D array of clusters. It will sort based on the first element.
To add more data, do the same thing and append the 2nd array of clusters to the first and repeat the sort.
05-17-2012 12:14 PM
so simple
07-09-2012 09:29 PM
Anyone has any idea how to convert the sorted array of clusters back to two separate arrays?
@Ravens Fan wrote:
Combine your two arrays into an array of clusters where the first element of the cluster is from the first array, and the 2nd element from the second array. There is a function in the cluster palette called Index and Bundle Cluster Array that will do that for you.
Then sort the 1-D array of clusters. It will sort based on the first element.
To add more data, do the same thing and append the 2nd array of clusters to the first and repeat the sort.
07-09-2012 09:41 PM - edited 07-09-2012 09:41 PM
Iterate through the array to unbundle the elements back into individual arrays.
Then go and kudo this idea. Why is there no function to reverse "Index & Bundle Cluster Array"