LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sort 2D Array With Header?

Solved!
Go to solution

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?

=====================
LabVIEW 2012


0 Kudos
Message 1 of 25
(7,322 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 25
(7,314 Views)
Solution
Accepted by topic author SteveChandler

 


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.

Message 3 of 25
(7,304 Views)

Cool. Sounds line an OpenG vi!

=====================
LabVIEW 2012


0 Kudos
Message 4 of 25
(7,299 Views)

Actually I don't know about cluster sort. I looked and can not find it even with quickdrop.

 

 

 

 

 

=====================
LabVIEW 2012


0 Kudos
Message 5 of 25
(7,285 Views)

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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 25
(7,275 Views)

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").

Download All
Message 7 of 25
(7,254 Views)

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

0 Kudos
Message 8 of 25
(6,378 Views)

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:

sort string array with timestamp.png

0 Kudos
Message 9 of 25
(6,357 Views)

Thanks Nathand

I have test the VI. But I got an error message.

Please have a look on it.

Why error?

Thanks

Download All
0 Kudos
Message 10 of 25
(6,327 Views)