Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Sorting 2-D Arrays [Labview] (http://www.chiefdelphi.com/forums/showthread.php?t=71988)

Kahn! 12-01-2009 20:03

Sorting 2-D Arrays [Labview]
 
I spent about 3 hours today circumventing the idea of sorting 2-D arrays in Labview. I had a 2-D array of 3 values. My plan was to reorder the array by one of the values while keeping the other values in the same index.

For example, this array:

[0] 6 14 28
[1] 7 81 4
[2] 1 15 38

I would want to sort it by column 3 making it this:
[0] 7 81 4
[1] 6 14 28
[2] 1 15 38

Does anyone know of a simple way to do this, or should I stick with my excessive, hard-to-follow code that I don't think I'll ever understand now that I've finished writing it?

psy_wombats 12-01-2009 20:10

Re: Sorting 2-D Arrays [Labview]
 
With only three elements, it may be enough to avoid "sorting" sorting altogether, and just use a few IF statements. Not practical for larger sorts, but it might be best in this case.

Uberbots 12-01-2009 21:21

Re: Sorting 2-D Arrays [Labview]
 
have you considered storing the 2d array as a 1-d array of clusters? that way you could store the item you want to sort by in the first slot and just do a 1-d built in sort.

Kahn! 12-01-2009 21:28

Re: Sorting 2-D Arrays [Labview]
 
Quote:

Originally Posted by Uberbots (Post 799769)
have you considered storing the 2d array as a 1-d array of clusters? that way you could store the item you want to sort by in the first slot and just do a 1-d built in sort.

As a matter of fact, I just got the same response from one of our mentors (aka my brother) and it's working perfectly.

Thanks.

Greg McKaskle 12-01-2009 21:58

Re: Sorting 2-D Arrays [Labview]
 
1 Attachment(s)
Unfortunately, there is no easy way to tell LV exactly how to sort more complicated data containers. LV deals with almost any type, but only 1D containers, sorted by first, then second, etc, and only in ascending order.

The attached snippet shows how to build an index array, then rebuild the 2D array based upon the indices.

Greg McKaskle


All times are GMT -5. The time now is 08:38.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi