Jump to content

Basic, small database type problem


Recommended Posts

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

Link to comment

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

Link to comment

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.

Link to comment

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?

Link to comment

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.

Link to comment

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.

Link to comment

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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.