LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array - doubt

Solved!
Go to solution

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?

0 Kudos
Message 1 of 11
(3,523 Views)
Solution
Accepted by topic author coimbra

In the future please attach the images directly to your post instead of placing them on ImageShack so people can directly access them. Smiley Wink

 

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.

Message 2 of 11
(3,513 Views)

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?

0 Kudos
Message 3 of 11
(3,509 Views)

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]
[URL=http://g.imageshack.us/img404/truect9.jpg/1/][IMG]http://img404.imageshack.us/img404/truect9.jpg/1/w640.png[/IMG][/URL]

[URL=http://imageshack.us][IMG]http://img396.imageshack.us/img396/7528/falsefw1.jpg[/IMG][/URL]
[URL=http://g.imageshack.us/img396/falsefw1.jpg/1/][IMG]http://img396.imageshack.us/img396/falsefw1.jpg/1/w640.png[/IMG][/URL]
Message Edited by coimbra on 11-08-2008 09:53 AM
0 Kudos
Message 4 of 11
(3,497 Views)
If by correct, you mean how you are trying to show some images, no. There is an 'Add Attachments' option right below the message body. Use that. If you have several images, zip them up and make one attachment. It would be better if you just attached your VI.
0 Kudos
Message 5 of 11
(3,483 Views)
Thank you. Here's my VI:
0 Kudos
Message 6 of 11
(3,480 Views)
In the True case, you should have used the Build Array function as shown by smercurio_fc and wired it correctly. Outside the loop, you did not create the array indicator correctly. Look carefully at the example. This is also very similar to the shipping example called Separate Array Values. Look at that as well.
0 Kudos
Message 7 of 11
(3,476 Views)
Can you edit my VI and attach it? Because i'm trying but i don't have any results 😞
0 Kudos
Message 8 of 11
(3,468 Views)

You really should start out with a few tutorial, because you are missing very basic fundamentals of LabVIEW programming.

  • The shift register needs to be initialized with an empty array, not with a scalar.
  • Inside the case structure, you want a built array, not an initialize array. Makes no sense!
  • You have an empty array container. You would need to populate it with elements of the correct type.

 

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!

 

 

Message Edited by altenbach on 11-08-2008 12:08 PM
0 Kudos
Message 9 of 11
(3,447 Views)

 Thank you 🙂

 

i'll see tutorials of this

0 Kudos
Message 10 of 11
(3,437 Views)