Showing results for 
Search instead for 
Did you mean: 

Sort 1D array of clusters by the second element in the cluster

Hello Folks,
I need to sort 1D array of clusters [Point (X & Y)] using the second element (Y) of the Point cluster. Can anyone guide!!!!
0 Kudos
Message 1 of 21
You can download my VI at:

it is called "Sort array using reference".
0 Kudos
Message 2 of 21
Cluster sorting uses the 1st item(item 0) in the cluster for sorting. I'm not sure if you can swap the order with a property node. Try to unbundle the data and rebundle with the y data first.
Message 3 of 21


Thanks for your reply. The "Sort array using reference" doesn't support the sorting of 1D array of cluster elements, based on 2nd element.

I will restate my question : --------------

Each Cluster Point (XY Point Coordinate values) in 1D array consist of --- X and Y value. X is the first value and Y is the second value in a cluster. I need to sort the 1D array using Y-value. The available "Sort 1D array" function in labview supports sorting using first element of the cluster (i.e. X-value) which I can't use for given problem. Any suggestions !!!


0 Kudos
Message 4 of 21


Here is a simple trick you can do to sort a cluster array by any element of the cluster:

Just unbundle the element you want to sort by, bundle this with the original cluster itself, do a sort, then unbundle out the original cluster elements.  Works every time... Smiley Happy


Message Edited by Darren on 03-22-200603:49 PM

DNatt, LV R&D
Message 5 of 21
I see Darren is a bit faster than me. Smiley Wink
Here's my solution (LabVEWI 7.0), it is pretty similar. Smiley Happy

Message Edited by altenbach on 03-22-200602:01 PM

LabVIEW Champion Do more with less code and in less time
Message 6 of 21
Thank you very much. It really works great...........................
0 Kudos
Message 7 of 21
By the way,

I always assumed that sorting such a cluster will always put sort according to the ENTIRE data set.  It just so happens that the first element is most significant.  Given two clusters with the same first element, the relative "size" of the second element will then determine the order, no?

I've always thought of the sort routine treating the entire cluster as a single (flattened) value.


PS would I be right in saying that altenbach's version is more efficient in terms of re-allocating memory?  It seems that Darren's version makes a copy of the entire array with an extra element whereas Altenbach's makes a small extra array for the sorting...... Maybe I've been doing too many coding challenges recently Smiley Tongue

PPS but of course, what happens when Altenbach's version recreates the array at the end?..... Oh my I need something to occupy me.

Message Edited by shoneill on 03-23-2006 02:04 PM

Message Edited by shoneill on 03-23-2006 02:05 PM

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 8 of 21
"would I be right in saying that altenbach's version is more efficient "
I believe you are right. I'd bet on Christian's version to win the challenge.
0 Kudos
Message 9 of 21
I guess a picture is worth 5 stars!!
Message 10 of 21