01-06-2011 12:08 PM
I am not trying to implement anything in particular. I am simply wondering what would be the best aproach to solving this problem if I were asked.
If I have a 2D array of strings with columns that contain text, others that contain numbers or timestamps, and the first row is the header, how would I go about sorting on a particular column? The results do not come from a database query so no "order by".
I was thinking about using ActiveX calls to Excel. Anoher possibility is to use a SQLite temporary table. How would you go about doing this?
Solved! Go to Solution.
01-06-2011 12:15 PM
I have used a cluster sort to do the sorting in similar situations in the past. But judging by your posting you know about that already and are looking for another option.
Ben
01-06-2011 12:20 PM
SteveChandler wrote:I was thinking about using ActiveX calls to Excel. Anoher possibility is to use a SQLite temporary table. How would you go about doing this?
In LabVIEW, of course!
Here's what I'd do:
1) Remove the header row, leaving a 2-D array of strings of the data
2) Extract the desired sort column. In a for loop, iterate through the resulting 1-D array of strings. Convert each string the appropriate representation and bundle it with the iteration count, so the output is an array of a cluster of two elements.
3) Use Sort 1-D Array to sort the array of clusters.
4) Iterate through the sorted array. Unbundle the counter element, grab that row from the original 2-D array, and add it to a new array.
5) Insert the header row into the sorted array.
01-06-2011 12:29 PM
Cool. Sounds line an OpenG vi!
01-06-2011 12:44 PM
Actually I don't know about cluster sort. I looked and can not find it even with quickdrop.
01-06-2011 01:06 PM
My bad!
A Cluster sort is not a function but rather a code construct. Nathand got you started but to extend the idea...
When sorting an array of clusters, LV looks at the first element in the cluster to do the sort. If there is a tie it looks at the second element in the cluster etc.
So by controling the cluster order you can get LV to sort on various collumns and do the tie breaking as required.
Ask if you are still confused.
Ben
01-06-2011 04:10 PM
First peel off the headers. Then use one of the attached VIs. "Sort_2D_Array_Str.vi" does a straight ASCII sort whereas "Sort_2D_Array_Str_AN.vi" does an alphanumerical sort (i.e. "2" precedes "10").
09-17-2013 12:54 AM
Hi
I have a 2D array. The first column is Data and Time. The date is in wrong order but time is right order. I want to re order the date without change time's order. How to do?
Please have a look the vi attached.
Thanks
09-17-2013 12:02 PM
I'm not sure why you added to a 2 year old thread rather than starting a new one since your question is different from the one originally posted here.
This code should do what you want:
09-18-2013 07:17 PM
Thanks Nathand
I have test the VI. But I got an error message.
Please have a look on it.
Why error?
Thanks