ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Conditional array sum

Solved!
Go to solution

Hi there,

 

I'm very new to labview so bear with me.

 

I would like to walk through the elements of an array that meet certain conditions and sum them, until the condition is not met.  I would then like to take that sum and build a new array, the second element being the element that did not meet the condition.  I would then like to continue from where I left off, but starting a new summation that would then be appended to my new array until the condition is not met, and so on...

 

For example

Given the array:

 

0.5

0.5

0.5

4

0.5

0.5

0.5

4

 

...would like to output..

1.5

4

1.5

4

 

I've been able to get a summation until the condition is not met using a while loop, however, I can't figure out how to continue from where I left off in the array.

 

If anyone can give me a point in the right direction that would be appreciated.

 

 

0 Kudos
Message 1 of 11
(5,031 Views)
It more convenient if you show us what you have done so far. As code NOT a picture. It is more easy to solve your problem this way. And your problem is not difficult to solve 😉


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 2 of 11
(5,028 Views)

Here is one example I have.  I didn't include any code before because I've tried so many different things and I would rather do it properly than try to try and "fix" my version.

 

This code sums everything in the array meeting the condition, but it's not correct.

0 Kudos
Message 3 of 11
(5,019 Views)

HERE.PNG

 

This should do it.  Interesting exercize.

Message Edited by Jeff Bohrer on 07-29-2009 01:03 PM

"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 11
(5,016 Views)
Solution
Accepted by Geir58

Try this:

 

 

 

You still need to deal with the condition where the last element does not meet the condition, but that would be easy to fix. Try it. 🙂

Message Edited by altenbach on 07-29-2009 11:32 AM
Download All
Message 5 of 11
(4,999 Views)

Thank you,

 

I've been having a hard time understanding shift registers but this is exactly what I needed.

0 Kudos
Message 6 of 11
(4,985 Views)

Be careful, as I mentioned, you still need to tweak it a bit.

  1. Return empty array if input is empty
  2. Work correctly if first element is not a match
  3. Work correctly if last elements are a match.

Here's one possible solution. Modify as needed.

 

 

0 Kudos
Message 7 of 11
(4,956 Views)

altenbach wrote:

Be careful, as I mentioned, you still need to tweak it a bit.

  1. Return empty array if input is empty
  2. Work correctly if first element is not a match
  3. Work correctly if last elements are a match.

Here's one possible solution. Modify as needed.

 

 


Thats why it was so interesting to solve.  see my previous post.  The code shown handels the above mentioned cases

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 11
(4,951 Views)

Of course if the arrays are large, you don't want to grow arrays inside loops. Here's an in-place solution that is probably better if performance is an issue.

 

(please verify correct operation). 😄

 

 

Message 9 of 11
(4,938 Views)

correct operation!

I've never even looked at that pallet before
(in 8 years)  Thanks for the eye opener!


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 11
(4,926 Views)