LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sorting a Table

I made this a long time ago.

Download All
0 Kudos
Message 11 of 27
(217 Views)

In the end, for columns that contain numeric data, I followed altenbach: Convert the column to floats, bundle each float with the string array for the corresponding line, sort the resulting array of clusters, unbundle to retrieve nicely ordered lines. Nice!

For alphanumeric columns, I did an explicit alphalogical bubble sort (courtesy of Jared_B from this 2010 forum post). I modified the sort so that whenever the algorithm swaps two values in the 1D array of strings, it also swaps the corresponding values in an array containing the line indices (0, 1, 2, ... n-1). I then use the resulting swapped array of indices to reorder the table lines. I believe this is jjohn1's keysort solution.

Thanks for all the input. Very helpful.

 

David

 

 

0 Kudos
Message 12 of 27
(180 Views)

@FlatCat wrote:

In the end, for columns that contain numeric data, I followed altenbach: Convert the column to floats, 


I don't remember mentioning anything about "floats", so I am not sure what you did.

 


@FlatCat wrote:

For alphanumeric columns, I did an explicit alphalogical bubble sort (courtesy of Jared_B from this 2010 forum post).


Did you try my solution with the "magic subVI". It works equally well on alphabetic, numeric or mixed strings with any number of mixed fields, so no column specific decision needs to ever be made. It also uses the stock LabVIEW sort, which might be more efficient than anything hand-coded. I'll probably add an input to select case sensitivity, though.

 

0 Kudos
Message 13 of 27
(147 Views)

OK, I cleaned up the code a little. See if this is useful.

 

The term "alphalogical" is a bit uncommon and google finds mostly links to the NI forum. Windows explorer calls it "Numerical" and that's what I am using.

 

altenbach_0-1768089857842.png

 

altenbach_1-1768089867628.png

 

 

 

 

 

0 Kudos
Message 14 of 27
(132 Views)

@altenbach wrote:

@FlatCat wrote:

In the end, for columns that contain numeric data, I followed altenbach: Convert the column to floats, 


I don't remember mentioning anything about "floats", so I am not sure what you did.

 


@FlatCat wrote:

For alphanumeric columns, I did an explicit alphalogical bubble sort (courtesy of Jared_B from this 2010 forum post).


Did you try my solution with the "magic subVI". It works equally well on alphabetic, numeric or mixed strings with any number of mixed fields, so no column specific decision needs to ever be made. It also uses the stock LabVIEW sort, which might be more efficient than anything hand-coded. I'll probably add an input to select case sensitivity, though.

 



Here's an alternate for your magic VI (requires LV 2020+).

paul_a_cardinale_0-1768100873128.png

 

0 Kudos
Message 15 of 27
(111 Views)

I don't remember mentioning anything about "floats", so I am not sure what you did.

I know beforehand whether any column contains purely numeric data, so for those columns I just used your original solution of converting the text to a DBL ("float") and bundling with the row strings before sorting. 

But yours and Paul's "magic" vi's are much more elegant, so I will look into adopting some form of those.  

0 Kudos
Message 16 of 27
(96 Views)

@paul_a_cardinale wrote:
Here's an alternate for your magic VI (requires LV 2020+).

Sorry, can't open it in 2020.

0 Kudos
Message 17 of 27
(92 Views)

@altenbach wrote:

@paul_a_cardinale wrote:
Here's an alternate for your magic VI (requires LV 2020+).

Sorry, can't open it in 2020.


Sorry, I wrote that incorrectly.  It actually requires 2021+.  However the only 2021 feature that it uses is the concatenating of strings by a tunnel.

Attached is a 2018 workaround.

0 Kudos
Message 18 of 27
(65 Views)

Ok. These really ARE magic. Such a satisfying and simple way to solve the problem, and one that I would never have thought of. Many thanks. 

0 Kudos
Message 19 of 27
(53 Views)

Yes, I got the gist of it from the picture

 

You are padding with spaces (i.e. a non-numeric character) while I am padding with zeroes (i.e. a numeric character)..

I am curious if there could be edge cases where it would make a difference, but haven't explored that.

 

One simplification would be to use the upper input of the format, eliminating your inner concatenation.

 

altenbach_0-1768150554547.png

 

Message 20 of 27
(47 Views)