07-29-2009 12:28 PM
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.
Solved! Go to Solution.
07-29-2009 12:37 PM
07-29-2009 12:57 PM
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.
07-29-2009 01:02 PM - edited 07-29-2009 01:03 PM
This should do it. Interesting exercize.
07-29-2009 01:29 PM - edited 07-29-2009 01:32 PM
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. 🙂
07-29-2009 01:56 PM
Thank you,
I've been having a hard time understanding shift registers but this is exactly what I needed.
07-30-2009 02:41 PM
Be careful, as I mentioned, you still need to tweak it a bit.
Here's one possible solution. Modify as needed.
07-30-2009 03:05 PM
altenbach wrote:Be careful, as I mentioned, you still need to tweak it a bit.
- Return empty array if input is empty
- Work correctly if first element is not a match
- 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
07-30-2009 04:14 PM
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). 😄
07-31-2009 09:17 AM
correct operation!
I've never even looked at that pallet before
(in 8 years) Thanks for the eye opener!