LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

adding cumulatively inside a while loop

How do I add a value to a value calculated in the previous iteration of the loop? I want to accumulate or sum all the previous values.
0 Kudos
Message 1 of 9
(4,760 Views)
You have to use a shift register.there is a good example in labview called running average.VI

Try this and see if it helps you.

Joe



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 2 of 9
(4,760 Views)
you can also use the feedback node to accomplish this if you like...

Dan
0 Kudos
Message 3 of 9
(4,760 Views)
Thanks Joe,
Thru numerous hair pulling sessions I found that the number being passed to the next iteration (the output from a single analog in box) was not actually a number, it's an array? By making an indicator for the output and looking at it on the front panel, there's a bunch more information there like the date, time, dt, and the AI data is the first element in an array of zeros. Why does NI do this? Why isn't the output from an AI box just the voltage number?

Anyway, I'll try not to rage. I used a sum array box (probably not the right way to do it) it converted the complicated output from the AI into a number and I was able to loop that thru a feedback node and add it to itself iteratively inside the while loop.

In the process I also
learned about shift registers so maybe that will come in handy in the future. I'll try to weigh that against wasting my whole day on this yesterday while raging that I would be finished if I just used QuickBasic and a $100 ComputerBoards card!
0 Kudos
Message 4 of 9
(4,759 Views)
Thanks for the help!

Maybe you can answer another question. Does NI have a pre-made integrating strip chart recorder for LabView? It seems like a no brainer, but I couldn't find one in LabView.

I'm using LabView to find the area under the curve as a peak comes out of a total organic carbon (TOC) analyzer, it's a piece of lab equipment.

It seems like there should be one out there for gas chromatographs too but I didn't see one of them either.

Any ideas? Or does someone have to write it themselves?
0 Kudos
Message 5 of 9
(4,759 Views)
if you right click the AI vi's you can select between Waveform , scaled array , binary array or scaled and binary array. the default is waveform. if you pick scaled array you will get an array of jsut voltage readings...

good luck

Dan
0 Kudos
Message 6 of 9
(4,759 Views)
You will have to write it yourself, there are lots of functions in labview that will allow you to do what you want. Just check out all the math functions. Or you could just use the formula node to do it.

Sorry I could not help you more.

Joe



Joe.
"NOTHING IS EVER EASY"
0 Kudos
Message 7 of 9
(4,759 Views)
In addition to what Dan said, it appears that you by mistake acquired several Analog Input channels while you had meaningful data coming only on one channel. You probably want to use AI Sample Channel.vi that measures the signal attached to one specified channel.

Regards,
Ankita A.
0 Kudos
Message 8 of 9
(4,759 Views)
Use the "Time Domain Math" ExpressVI and enable "Integral" to measure the integral of your array.

If you prefer lower level functions then use the "Add Array Elements" function and divide the result with number of measurements per unit. You will then have the integral of the array.

Best regards
Philip C.
Applications Engineer
National Instruments
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 9 of 9
(4,759 Views)