From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
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!!!!
Thanks.
 
Manu
0 Kudos
Message 1 of 22
(20,274 Views)
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 22
(20,270 Views)
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 22
(20,266 Views)

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 22
(20,258 Views)

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... 🙂

-D

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

Message 5 of 22
(20,252 Views)
I see Darren is a bit faster than me. 😉
 
Here's my solution (LabVEWI 7.0), it is pretty similar. 🙂

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

Download All
Message 6 of 22
(20,244 Views)
Thank you very much. It really works great...........................
 
Manu
0 Kudos
Message 7 of 22
(20,237 Views)
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 22
(20,223 Views)
"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
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 22
(20,206 Views)
I guess a picture is worth 5 stars!!
Message 10 of 22
(20,195 Views)