cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

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

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!!!!
Thanks.
 
Manu
0 Kudos
Message 1 of 21
(10,839 Views)

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

You can download my VI at:

http://www.jyestudio.com/visecurity/resources.html

it is called "Sort array using reference".
www.vartortech.com
0 Kudos
Message 2 of 21
(10,835 Views)

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

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
(10,831 Views)

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

Hello,

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 !!!

Manu

0 Kudos
Message 4 of 21
(10,823 Views)
Highlighted

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

Hello,

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

-D

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

DNatt, LV R&D
Message 5 of 21
(10,817 Views)

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

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
(10,809 Views)

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

Thank you very much. It really works great...........................
 
Manu
0 Kudos
Message 7 of 21
(10,802 Views)

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

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.

Shane.

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
(10,788 Views)

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

"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.
 
Ben
0 Kudos
Message 9 of 21
(10,771 Views)

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

I guess a picture is worth 5 stars!!
Message 10 of 21
(10,760 Views)