11-08-2008 07:21 AM
hello. i've a work to do that consists in: we have to create a array of random numbers (done) and the user gives a number that he chooses. We have to create a new array with all the numbers of the random array that are bigger than the number of the user.
i've made this: http://img291.imageshack.us/my.php?image=helpaipeop3.jpg
my doubt is: how do i create a new array with all the numbers that are bigger than the number?
Solved! Go to Solution.
11-08-2008 08:23 AM
In the future please attach the images directly to your post instead of placing them on ImageShack so people can directly access them. ![]()
To answer your question: You are not understanding dataflow. Since there is no data dependency between the 2 loops then the 2 loops will run at the same time. However, the bottom loop will run with empty arrays since they are only populated once the top loop ends. Your incorrect use of local variables is a mistake, and the probably the number one reason why we see programs not working correctly. You have to ensure the arrays are populated before you try to use them. That said, there is no need for 2 loops to begin with. Perform the comparison right there where you are generating the random number. Use a shift register to accumulate an array. If the random number is larger than the control, then add it to the array. If not, pass the array through. Use a case structure. Like this:
To learn more about LabVIEW it is recommended that you go through the tutorial(s) and look over the material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.
11-08-2008 08:42 AM
Addendum: The above is the "easy to understand" method, and suitable for small arrays. An alternative method is to generate your array of random numbers with the loop. Then, sort the array and find the index where the numbers are larger than your target. Then, just take an array subset.
Seems like a standard homework question, doesn't it?
11-08-2008 09:50 AM - edited 11-08-2008 09:53 AM
hummm.. i think i understand now. except the "shift register" part...
i'm getting some "conversion" problems , i still don't understand that.
btw, is this correct?
[URL=http://imageshack.us][IMG]http://img404.imageshack.us/img404/64/truect9.jpg[/IMG][/URL]
11-08-2008 12:51 PM
11-08-2008 12:58 PM
11-08-2008 01:14 PM
11-08-2008 01:30 PM
11-08-2008 02:07 PM - edited 11-08-2008 02:08 PM
You really should start out with a few tutorial, because you are missing very basic fundamentals of LabVIEW programming.
Here's a quick rewrite, maybe it can give you some ideas. SInce you are dealing with integers, you want blue for the arrays. 🙂
Good luck!
11-08-2008 04:33 PM
Thank you 🙂
i'll see tutorials of this