07-25-2012 01:47 PM
I have a 2D array with 3 columns and 1000 rows and I need to sort all these 1000 rows in terms of their values in the third column. Now I split the three columns into three individual 1D array and sorted the 1D array of the third column. My question is how to make the first two columns change their orders following the third column? For exsample:
A=[
0 0 -1
1 0 0
2 1 3
5 4 2
6 1 1]
how to sort it into:
B=[
2 1 3
5 4 2
6 1 1
1 0 0
0 0 -1];
07-25-2012 02:06 PM - edited 07-25-2012 02:08 PM
Move your question to the LabVIEW section of the forum. This section (BreakPoint) is for side discussions, more often than not, unrelated to LabVIEW. There's a trick with using a cluster to hold the original row index and the current value, and then you can sort by the current value and the orginal index goes along for the ride. Then you can use the new order to reorder your array. Clear? haha.
Move your question to the LabVIEW forum and people will know what I'm getting at.
07-25-2012 02:14 PM - edited 07-25-2012 02:17 PM
There might be a way to do this without making a copy of the data, but here ya go. I caved 🙂
Edit: I noticed afterwards you needed it to be greatest to least. After you sort the array, do a reverse array and it will do what you want.
07-25-2012 02:27 PM
Here is an old related discussion...
07-25-2012 05:04 PM
For:
Thank u very much for providing me this information!
Frank
07-25-2012 05:04 PM
Altenbach:
Thanks!
Frank