Showing results for 
Search instead 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)? 
0 Kudos
Message 1 of 10

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?

0 Kudos
Message 2 of 10
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!
0 Kudos
Message 3 of 10
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?
0 Kudos
Message 4 of 10

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.


DNatt, NI
Message 5 of 10
Here's a simple example showing Darrens suggestion. (LabVIEW 7.0)
Message 6 of 10
Excellent!  Thanks for the advice
0 Kudos
Message 7 of 10

Many thanks. That is what I am looking for.



0 Kudos
Message 8 of 10

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



Download All
Message 9 of 10

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

0 Kudos
Message 10 of 10