# LabVIEW

cancel
Showing results for
Did you mean:

## how to sort a 2D array?

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];

Message 1 of 6
(9,744 Views)

## Re: how to sort a 2D array?

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.

Message 2 of 6
(9,740 Views)

## Re: how to sort a 2D array?

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.

Message 3 of 6
(9,737 Views)

## Re: how to sort a 2D array?

Here is an old related discussion...

Message 4 of 6
(9,725 Views)

## Re: how to sort a 2D array?

For:

Thank u very much for providing me this information!

Frank

Message 5 of 6
(9,704 Views)

Altenbach:

Thanks!

Frank

Message 6 of 6
(9,703 Views)