キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

Conditional array sum

解決済み
解決策を見る

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 件の賞賛
メッセージ1/11
4,964件の閲覧回数
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 件の賞賛
メッセージ2/11
4,961件の閲覧回数

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 件の賞賛
メッセージ3/11
4,952件の閲覧回数

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 件の賞賛
メッセージ4/11
4,949件の閲覧回数
解決策
受理者 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
すべてをダウンロード
メッセージ5/11
4,932件の閲覧回数

Thank you,

 

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

0 件の賞賛
メッセージ6/11
4,918件の閲覧回数

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 件の賞賛
メッセージ7/11
4,889件の閲覧回数

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 件の賞賛
メッセージ8/11
4,884件の閲覧回数

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

 

 

メッセージ9/11
4,871件の閲覧回数

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 件の賞賛
メッセージ10/11
4,859件の閲覧回数