LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Odd/even

how do you find the sum of all odd numbers from an array. The array in question is coming out of a loop. Help please.

 

This is what I have so far. when i run it I do not get an output for the sum of the odd numbers.

Screen Shot 2021-11-18 at 1.34.51 PM.png

 

0 Kudos
Message 1 of 9
(3,700 Views)

First, you have to determine how you are going to tell an even number from an odd one?  Have any ideas?  To help you on your voyage of discovery, here is the definition of an even number.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 9
(3,693 Views)

It probably does not matter where the array comes from, right?

 

I assume you have integers (blue datatype), so to check odd/even, all you need to inspect is the LSB (e.g. doing a logical AND with 1 and see if the result is zero or not).

 

So, all you need is another autoindexing FOR loop where you process element by element and conditionally add each to a initialized shift register if it is odd. If you have control over the previous loop, you could even do the processing right there... This is quite simple, and if your code is larger than a postage stamp, you are doing something wrong 😄

 

See how far you get and attach your code if you get stuck and ask specific questions.

0 Kudos
Message 3 of 9
(3,691 Views)

@altenbach wrote:

It probably does not matter where the array comes from, right?

 

I assume you have integers (blue datatype), so to check odd/even, all you need to inspect is the LSB (e.g. doing a logical AND with 1 and see if the result is zero or not).

 

So, all you need is another autoindexing FOR loop where you process element by element and conditionally add each to a initialized shift register if it is odd. If you have control over the previous loop, you could even do the processing right there... This is quite simple, and if your code is larger than a postage stamp, you are doing something wrong 😄

 

See how far you get and attach your code if you get stuck and ask specific questions.


You ruined all the fun.  I was suggesting starting from the very beginning.  😄

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 9
(3,687 Views)

I have edited my post for you to see my code. could you please tell me what i am doing wrong . Thanks!

0 Kudos
Message 5 of 9
(3,682 Views)

@Tayra! wrote:

I have edited my post for you to see my code. could you please tell me what i am doing wrong . Thanks!


The first thing you're doing wrong is not attaching your VI.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 9
(3,678 Views)

@billko wrote:
You ruined all the fun.  I was suggesting starting from the very beginning.  

Sorry, your reply was not there when I composed my reply.

 

Either way they'll learn something. Even translating my words into graphical code could be quite a challenge for a newbie. Blindly basing odd/even determination on division as you suggested will probably be quite messy, because the typical division outputs orange and then we need to separate the fractional and integer parts and do comparison on floating point numbers, which is another can of worms (Probably not here, but in general). Yes, there are better types of "divisions" (e.g. one that starts with the letter Q), but they are not obvious for the new student. 😄

 

 

Message 7 of 9
(3,677 Views)

@Tayra! wrote:

I have edited my post for you to see my code. could you please tell me what i am doing wrong . Thanks!


All we see is a photo of a blurry diagram, partially covered by the front panel.

 

Place indicators (or probes) after the AND and after the multiplication to see what's happening. Simple troubleshooting!

 

If you want real help, you need to attach your actual VI. Please use "save for previous" if you use LabVIEW 2021.

0 Kudos
Message 8 of 9
(3,673 Views)

Obviously, your code is sound, because it works for me, so there must be something else going on.

 

altenbach_0-1637261973802.png

 

Some simple things to check:

 

  1. Are there any local variables or value property nodes of your result indicator?
  2. Are all wires really connected as you think they are?
  3. From the picture there seems to be a top-level while loop (truncated in the view). What else is there?
  4. did you really run the VI?
  5. ...
0 Kudos
Message 9 of 9
(3,659 Views)