Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   NI LabVIEW (http://www.chiefdelphi.com/forums/forumdisplay.php?f=182)
-   -   Basic Labview Programming Questions (http://www.chiefdelphi.com/forums/showthread.php?t=69527)

tivomatic 12-10-2008 14:03

Re: Basic Labview Programming Questions
 
1 Attachment(s)
I am trying to write a Labview vi that takes a one dimensional numerical array, for example A= 5,4,3,2,1, and sorts the values in ascending order. We do not want to use the sort array operator since the whole purpose is to practice using labview. Although I can write this no problem using Basic, I am having trouble in Labview. :confused: . I have attached the vi.

Thanks.

Joe Ross 12-10-2008 15:21

Re: Basic Labview Programming Questions
 
1 Attachment(s)
Quote:

Originally Posted by tivomatic (Post 769846)
I am trying to write a Labview vi that takes a one dimensional numerical array, for example A= 5,4,3,2,1, and sorts the values in ascending order. We do not want to use the sort array operator since the whole purpose is to practice using labview. Although I can write this no problem using Basic, I am having trouble in Labview. :confused: . I have attached the vi.

Thanks.

I've attached a version that does what I think you want. The main thing you needed was a shift register (or feedback node) to take your changed array and feed it back so it could be operated on. The way you had it, each loop it was always operating on the original array. I must admit that this has been the thing I've messed up the most in LabVIEW.

You'll need another loop of some type to finish sorting. You can also use the array size VI for the input to the count terminal input of the for loop.

BitTwiddler 13-10-2008 13:25

Re: Basic Labview Programming Questions
 
1 Attachment(s)
Quote:

Originally Posted by Joe Ross (Post 769856)
I've attached a version that does what I think you want. The main thing you needed was a shift register (or feedback node) to take your changed array and feed it back so it could be operated on. The way you had it, each loop it was always operating on the original array. I must admit that this has been the thing I've messed up the most in LabVIEW.

You'll need another loop of some type to finish sorting. You can also use the array size VI for the input to the count terminal input of the for loop.

Taking Mr. Ross' vi a bit further, I've modified it to swap array elements without overwriting the ith array element. Still needs another loop to control the number of passes through the array in order to propagate all of the changes each pass makes.

Kevin Sevcik 13-10-2008 14:24

Re: Basic Labview Programming Questions
 
Well that last VI is mostly correct, aside from either a second FOR loop to run it n-1 times, or a while loop that will stop if it didn't make any swaps in the last run of that inner FOR loop... But seeing Bubble Sort implemented in Labview seems very very wrong to me. There's a reason NI has VIs like this already made, after all.

Alan Anderson 13-10-2008 14:47

Re: Basic Labview Programming Questions
 
Quote:

Originally Posted by Kevin Sevcik (Post 770015)
But seeing Bubble Sort implemented in Labview seems very very wrong to me.

I enthusiastically agree. Bubble Sort is a highly procedural algorithm, something which LabVIEW does only grudgingly. I wonder if a Partition Sort would more closely align with LabVIEW's data-flow nature.

But I think sorting is the kind of operation that should be implemented by people having deep knowledge of the runtime environment, and not used as an exercise in learning how to use a data-driven programming language.

Greg McKaskle 13-10-2008 18:29

Re: Basic Labview Programming Questions
 
1 Attachment(s)
If this is for learning purposes, then I see nothing wrong with it. In fact I've attached a few other implementations of sort, which will hopefully show some of the tricks and syntax with arrays as well as the relative performance.

[ATTACH]More sorting[/ATTACH]

If you decide to use a Bubble Sort on your robot, well then perhaps you'd like to build your own chain too.

Greg McKaskle


All times are GMT -5. The time now is 11:30.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi