# LabVIEW

cancel
Showing results for
Did you mean:

## Neat way of sorting a 3d array by its page ?

Can anyone supply an example of sorting a 3d array by its page (index)?
Message 1 of 10
(2,440 Views)

## Re: Neat way of sorting a 3d array by its page ?

Arrays are sorted by their indices by definition, right?! 😉

Can you explain in a few more words what you are trying to do? Maybe give an example?

Message 2 of 10
(2,435 Views)

## Re: Neat way of sorting a 3d array by its page ?

In order to sort, you have to have a vector (1D array) to sort by, so you need to provide the "row" and "column" so you can get your 1D array. Then you sort it and use the indexes to shift the pages to the new order. Attached is an image of the code from the OpenG Sort 2D Array VI. You can modify it to do what you want.

___________________
Try to take over the world!
Message 3 of 10
(2,423 Views)

## Re: Neat way of sorting a 3d array by its page ?

I have been able to provide row/col to parse out a 1d array, and sort that array.  The problem I see is how do I then match the original "pages" that belonged to this newly sorted array?  For example, lets say we have a 3d array with strings.  The first row/col of every page is a "label".  The 2nd row contiains multiple columns with information.  I want to sort the pages by the first row/col.  I can index this 3d array by row 0 and col 0, giving me a 1d array of all the labels.  I can then sort the 1d array.  But, how do I then match the new 1d array to the pages themselves?
Message 4 of 10
(2,403 Views)

## Re: Neat way of sorting a 3d array by its page ?

The easiest way to do this would be to create a cluster, where the first element in the cluster is the element from the 3D array you want to sort by, and the second element is the entire page associated with that sorting element.  Then wire this cluster into the Sort 1D Array function.  Take the sorted output and unbundle the pages in a loop, and rebuild them into the 3D array.  This trick is possible because the Sort 1D Array function allows you to sort a cluster array based on the first element in the cluster.

-D

DNatt, NI
Message 5 of 10
(2,393 Views)

## Re: Neat way of sorting a 3d array by its page ?

Here's a simple example showing Darrens suggestion. (LabVIEW 7.0)
Message 6 of 10
(2,380 Views)

Message 7 of 10
(2,375 Views)

## Re: Neat way of sorting a 3d array by its page ?

Many thanks. That is what I am looking for.

xg

Message 8 of 10
(1,767 Views)

## Re: Neat way of sorting a 3d array by its page ?

Wow, this is an old thread!!! 😮

Since my code example above has just been kudoed, I am taking the liberty to refresh the code a little bit. I believe it is more memory efficient to NOT drag the entire 3D array through the sorting mechanism, especically if large 3D arrays are involved. Here's what I would do today instead (same result!)

Message 9 of 10
(1,757 Views)

## Re: Neat way of sorting a 3d array by its page ?

thanks for the update. great!!  I will have a go

Message 10 of 10
(1,741 Views)