09-05-2012 04:11 AM
I have a simple VI..
First generate a 2D random numbers array. From this 2D array I have to show only the even numbers in a 1D array.
I will thank you a lot!
Solved! Go to Solution.
09-05-2012 04:25 AM
Here's one way...
Auto index the 2D array using a nested FOR loop (FOR inside a FOR loop). If the element of the array has no remainder when divided by 2, then it's an even number hence should be added to your 1D array.
This is straight forward stuff...
Try a combination of the following labVIEW components
Tips:
- For Loops
- Quotient & Remainder
- =0
- Shift Register
- Build array
Strokes
(There may be better/other/more efficient/less efficient etc etc solutions to this problem)
09-05-2012 05:11 AM
take a look to what I've done.. I got a conflict with the case structure I used, this is, when the remainder is 0 then, store in an array, but if it's false(by default because in tru case is just wired) then store a zero.. My conflict was that I finally got an array of even numbers and zeros as the quantity of odd numbers.
What I've done is resize the 2D array into a 1D and then sort it, then reverse the order so that the zeros of the array are all after the even numbers, then I used 'delete from array' from the index that zeros start, finally I got an array with only the even numbers, I have no problem with the result because the excercise asks me a range of random numbers from 13 to 69... but if it was from 0 to x all what I've done is no more efficient because I'd need the possible zeros that would appear by random generating.. I don't dominate arrays in labview, surely you have a completely more efficient solution to what I want
09-05-2012 05:14 AM - edited 09-05-2012 05:17 AM
Hi vinu,
Please post a screenshot of your block diagram
Try some simple checks for even number:
09-05-2012 05:33 AM
Try this...
Again I'm not advocating this to be the best available solution...
09-05-2012 07:50 AM
There's no need for the waits in this situation. You want to process that data as quickly as possible.
The other thing you should be careful about is that doubles often have fractional differences. This example would be better off using an integer data type (like I32).
Otherwise, the code looks good to me.
09-05-2012 02:40 PM
Hey Strokes.. That Block diagram seems efficient.. I don't know what array function is inside the true case.. it seems to be initialize array...
09-05-2012 02:43 PM
hehe.. I finally realized that it was build array
09-05-2012 02:46 PM
@vinus_1355 wrote:
Hey Strokes.. That Block diagram seems efficient.. I don't know what array function is inside the true case.. it seems to be initialize array...
Inside the true case is a Build Array. The false case should be simply passing the array straight through.
09-05-2012 02:49 PM
Hey Strokes.. but what did you do for the false case?