LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get a sub-array of even numbers from an array?

Solved!
Go to solution

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!

0 Kudos
Message 1 of 12
(8,893 Views)
Solution
Accepted by topic author vinus_1355

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)

Message 2 of 12
(8,887 Views)

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

0 Kudos
Message 3 of 12
(8,870 Views)

Hi vinu,

             Please post a screenshot of your block diagram

             Try some simple checks for even number:

            

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks as kudos only:)
0 Kudos
Message 4 of 12
(8,867 Views)

Try this...

 

Extract Odd Numbers From 2D Array.png

 

Again I'm not advocating this to be the best available solution...

Message 5 of 12
(8,860 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 12
(8,829 Views)

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...

0 Kudos
Message 7 of 12
(8,810 Views)

hehe.. I finally realized that it was build array

 

0 Kudos
Message 8 of 12
(8,808 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 12
(8,803 Views)

Hey Strokes.. but what did you do for the false case?

0 Kudos
Message 10 of 12
(8,801 Views)