Scooter_X Posted April 10, 2009 Report Share Posted April 10, 2009 Hey everyone. I'm working on a project for my LabVIEW class in which we're supposed to design software that senses and outputs a whole bunch of information about a Pinewood Derby race. Currently, I'm stuck on a pretty basic part where I want to be able to assign a string to a number (a race time, for example) in an array of some sort and be able to sort that array according to that number. So I have Racer X with a time of 5 sec, Racer Z with a time of 4 sec, and Racer Q with a time of 6 sec. I want to sort that so that racer Z is on top followed by X and Q. See what I'm saying? Anyway, I can't figure it out because I'm trying to change my number into a string, then concatenating them and finally putting them into an array. But then I can't sort them numerically. I've done a little bit with clusters too but can't figure much out. I'm a bit stuck. Any suggestions? I would really appreciate it. Thanks a lot!! -Scooter Quote Link to comment
Tim_S Posted April 10, 2009 Report Share Posted April 10, 2009 QUOTE (Scooter_X @ Apr 8 2009, 10:49 PM) I'm working on a project for my LabVIEW class in which we're supposed to design software that senses and outputs a whole bunch of information about a Pinewood Derby race. Thanks for pointing out this is for a class. A nudge in the "right direction" is that LabVIEW can sort an array of clusters. Tim Quote Link to comment
ejensen Posted April 10, 2009 Report Share Posted April 10, 2009 QUOTE (Tim_S @ Apr 9 2009, 07:41 AM) A nudge in the "right direction" is that LabVIEW can sort an array of clusters. I was curious how this worked, so I played with it for a few minutes. I thought I'd share a bit more advice that should be useful. When sorting an array of clusters, sort 1d array sorts by the first item in the cluster. I assume you want the name first and the time second in the cluster (this just seems like the 'right way' to me). If you just sort the array with a string and a numeric, you get an alphabetical sort on the strings. If you don't care about the order of items in your cluster, just put the number first and sort. Assuming you want the name first, you'll have to index the array, break the cluster apart, reverse the order of elements, reindex the array, sort the array, then index the array, swap the values back, reindex and display. It's not as hard as it sounds. Just play with bundle/unbundle and autoindexing on for loops. Also, there may be a much easier way to do this that I'm unaware of. Quote Link to comment
jdunham Posted April 10, 2009 Report Share Posted April 10, 2009 QUOTE (ejensen @ Apr 9 2009, 06:02 AM) Also, there may be a much easier way to do this that I'm unaware of. No, there's not. Quote Link to comment
jzoller Posted April 11, 2009 Report Share Posted April 11, 2009 QUOTE (jdunham @ Apr 9 2009, 12:52 PM) No, there's not. Agreed, if you have an array of clusters. Using parallel arrays of results drops some of the complexity, though you still end up doing the index-and-sort routine. Joe Z. Quote Link to comment
asbo Posted April 11, 2009 Report Share Posted April 11, 2009 QUOTE (jzoller @ Apr 9 2009, 11:20 PM) Using parallel arrays of results drops some of the complexity, though you still end up doing the index-and-sort routine. How do you figure, exactly? If you use two separate arrays, how are you going to sort the string array according to the sorting of the numeric array? Quote Link to comment
jdunham Posted April 11, 2009 Report Share Posted April 11, 2009 QUOTE (asbo @ Apr 10 2009, 03:58 AM) How do you figure, exactly? If you use two separate arrays, how are you going to sort the string array according to the sorting of the numeric array? Actually we do that all the time. You take the sort array and bundle it with the index terminal inside the FOR loop. Then you sort this new array of clusters, and put it back into a FOR loop and unbundle the new clusters. Then you have a sorted array of indexes which you can use against your other data. It's still easier to make an array of clusters and sort that, but if you already have the arrays, then use this technique. - Jason http://lavag.org/old_files/monthly_04_2009/post-1764-1239376717.png' target="_blank"> Quote Link to comment
crelf Posted April 11, 2009 Report Share Posted April 11, 2009 QUOTE (asbo @ Apr 10 2009, 07:58 AM) How do you figure, exactly? If you use two separate arrays, how are you going to sort the string array according to the sorting of the numeric array? http://lavag.org/old_files/monthly_04_2009/post-181-1239377374.png' target="_blank"> Quote Link to comment
asbo Posted April 11, 2009 Report Share Posted April 11, 2009 Ahh, I see what you're going for now. I guess I didn't read ejensen's explanation of sorting the string/numeric cluster closely enough to follow the thread. It's a shame that LabVIEW doesn't have built-in associative arrays - I wildly abused those guys in PHP. Quote Link to comment
Mark Yedinak Posted April 11, 2009 Report Share Posted April 11, 2009 It would be nice if LabVIEW provided a generic sort algorithm that the developer could plug a custom comparison VI into it. C++ has this capability so they have a very efficient sort algorithm and all you need to provide is a view of the data structure and a comparison function. This way you can efficiently sort an array of any data type. This would be a very nice addition to LabVIEW. Imagine being able to sort arrays of clusters easily with the additional ability to be able to sort on more than just the first element. Quote Link to comment
jdunham Posted April 11, 2009 Report Share Posted April 11, 2009 QUOTE (Mark Yedinak @ Apr 10 2009, 11:15 AM) It would be nice if LabVIEW provided a generic sort algorithm that the developer could plug a custom comparison VI into it. C++ has this capability so they have a very efficient sort algorithm and all you need to provide is a view of the data structure and a comparison function. This way you can efficiently sort an array of any data type. This would be a very nice addition to LabVIEW. Imagine being able to sort arrays of clusters easily with the additional ability to be able to sort on more than just the first element. Of course LabVIEW does sort on more than the first element of the cluster, but yes, it would be nice if you could chose the element order rather than having to rebundle your cluster. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.