LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to sort an array in Even and odd parts

Hey im trying to sort 1D array into two different arrays i.e. Even array and odd array.. please help me out..

0 Kudos
Message 1 of 40
(7,405 Views)

Hello T_reX, and welcome to the forum.

 

To start off- what have you attempted already?  Do you have code that you are trying to modify, or is this a new project?  Where is your data coming from, and what format is it in - integers, double-precision floating point decimal values, strings?  How many values do you need to process?

 

If you're working with integer values, the quotient & remainder function is very handy for determining whether or not a number is even or odd- use 2 as an input for Y and the remainder will tell you if the integer is even or not.

 

Regards,

Tom L.
0 Kudos
Message 2 of 40
(7,395 Views)

Here 

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 3 of 40
(7,378 Views)

Arrays mod.png

 

Wow Ranjeet......Nice Answer ( May be I am wrong that question is not very clear ).

and here we all are trying to tell new users dont use locals, what is auto indexing for loop, why and when not to use functions like insert array blah blah.......

0 Kudos
Message 4 of 40
(7,362 Views)

After posting , i saw that your reply marked as solution Smiley Happy

he got what he needed and after few years with same habit he will be developing big projects and abusing LabVIEW.

 

0 Kudos
Message 5 of 40
(7,359 Views)

man plz don't get me wrong... but i got what i was looking for ... no need to fight on that topic now..

 

thank you...

0 Kudos
Message 6 of 40
(7,357 Views)

There you go.

Best of luckSmiley Wink

0 Kudos
Message 7 of 40
(7,352 Views)

@Neos wrote:

Arrays mod.png

 

Wow Ranjeet......Nice Answer ( May be I am wrong that question is not very clear ).

and here we all are trying to tell new users dont use locals, what is auto indexing for loop, why and when not to use functions like insert array blah blah.......


There are thousand way to do this. I did this way. Access of anything is bad(and so is local variable). Using local variable is not a crime.

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 8 of 40
(7,349 Views)

The use of Index Array is Rube-Goldberg since you are auto-indexing the array. Just connect the auto-index output to the Quotient & Remainder function.

0 Kudos
Message 9 of 40
(7,303 Views)

@T_reX wrote:

man plz don't get me wrong... but i got what i was looking for ... no need to fight on that topic now..


Nobody is fighting, we are just having your best interest in mind.

 

You'll be well advised to basically ignore that solution and find something a bit more reasonable. if you learn LabVIEW this way, you'lll have unsurmountable problems later when the task gets just a little bit more complex. Bad habits are hard to break so learn the right way with simple problems from the beginning.

 

This seems to be homeweork. As a teacher I would give that solution a failing grade (minimal credit for giving the right result but with huge deductions for horrible coding style).

 

Now go back to an empty diagram, start from scratch and do something that does NOT have local variables.

  1. Use autoindexing
  2. Don't use any local variables, they are not needed here.
  3. Learn about shift registers (I am sure you learned about them in class!)
  4. Use "built array" instead of "insert into array" (for now, unless you implement #8 for extra credit ;)).
  5. Don't write to the indicators with every iteration of the loop, but just once after the loop has finished.
  6. Keep controls and indicators on the top diagram, not inside structures.
  7. Don't use any comparison operations. Case structures can handle integers directly.
  8. Extra credit for a solution that does not resize arrays inside the loop and operates mostly "in place".
  9. ... and finally, use a more common integer representation. U8 is too limiting.

In your future job you might have to deal with large arrays. In this case, the given solution will be many orders of magnitude slower and less efficient. It could take minutes to do what better code could do in milliseconds. Yes! Really!!! Coding style like this could get you fired in most places of work. 😞

 

See what you can come up with and post it here so we can help you improve further. This is a trivially simple beginners problem, so do your best. Shouldn't take more than a few minutes to modify. Try it! Good luck!

0 Kudos
Message 10 of 40
(7,290 Views)