Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

For loop and data addition

Solved!
Go to solution

I want to add the data from array index 5 to 10. so I initialize the index from 5 and by using the for loop I am changing the index value and adding the data with previous data and it shows in sum. but problem when for loop is over the sum data is still adding with previous data history .Ii want to reset the sum after complete a for loop. same I want to substract the new sum data to previous sum data in the last section of this program. but the substract keep the previous history . How to solve it.

 

SUMANSAURAV_0-1648468521307.png

 

0 Kudos
Message 1 of 9
(2,216 Views)

You can right-click on the Feedback Node and chose to "Move Initializer One Loop Out".  This will allow you to reinitialize the values in the Feedback Node at the beginning of the loop.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 9
(2,209 Views)

Thank you. 

Ya, it is working for addition. now for the subtraction part, I want to subtract sum data which is present in sum with previous sum and it keep same result until the next sum data came.

0 Kudos
Message 3 of 9
(2,201 Views)
Solution
Accepted by topic author SUMANSAURAV

Looking at your comment, I conclude you do not even need the FOR loop.  Just use Array Subset to get the array elements starting at your starting index and then use Add Array Elements to do the sum.

 

As far as your subtraction, I'm not completely sure what you are trying to do.  But I think you are trying to find the difference in the sum between iterations of the loop.  If that is the case, then you need to wire the sum to the input of the Feedback Node, not the subtraction result.

 

Additionally, you need a clean way to stop your loop instead of relying on the Abort button.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 9
(2,192 Views)

Thank you very much .

 

For loop is used to collect the data from the array. 

 

How to synchronize the Part 1 means for loop to the outer part2 ,because the out part is little faster then part 1 . part 2 to is not able to subtract the data which is coming from the loop.  

0 Kudos
Message 5 of 9
(2,177 Views)

SUMANSAURAV_0-1648532126285.png

The nth  value is coming and the (n-1)th value is subtracting with nth . then the indicator will show the subtract value. now the (n-1) value will update with nth value and again the new value will come in the nth place. and this will carry out for inf time. how to make this logic. please help me. 

0 Kudos
Message 6 of 9
(2,175 Views)

@SUMANSAURAV wrote:

The nth  value is coming and the (n-1)th value is subtracting with nth . then the indicator will show the subtract value. now the (n-1) value will update with nth value and again the new value will come in the nth place. and this will carry out for inf time. how to make this logic. please help me. 


The Feedback Node's output is your N-1 value.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 9
(2,157 Views)

The feedback output value should be [ nth - (n-1)th ]. The (n-1)th term should update with nth term and the nth term will take the new data.

0 Kudos
Message 8 of 9
(2,151 Views)

@SUMANSAURAV wrote:

The feedback output value should be [ nth - (n-1)th ]. The (n-1)th term should update with nth term and the nth term will take the new data.


No, the indicator should be [(nth - (n-1)th].  The Feedback Node is to hold the (n-1)th value, being updated with the nth value each iteration.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 9
(2,146 Views)