# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution
Highlighted

## storing and averaging value

Hi All,

I have a program which I am acquiring samples from NI9201 and output as analog dbl. I want to also calculate an average value over 10 samples and output that as well. After setting up the code and running, there is no difference in the calculated "Average" values and the raw reading as displayed by the two separate waveform. Could anyone shed a light on this?

Thanks!

Message 1 of 6
(462 Views)
Highlighted

## Re: storing and averaging value

The waveform charts looks the same because they are the same! Your for loop is simply adding a number to itself 10 times and then dividing by 10, so no averaging is occurring. Try the Mean PtByPt VI with a sample length of 10.

Message 2 of 6
(452 Views)
Highlighted

## Re: storing and averaging value

Hi Greg,

Thanks for the reply! Yes I noticed that as well right after I posted this.

I will try your suggestions. Although I am curious as to why it wouldnt work for this application, Could you please explain? I actually tried with a random number generator in a while loop with this for loop and it did take the average since each time the value enters the for loop is different. My speculation was each time it will acquire a different value and store into the for loop for N times then executes the average calculation.

Thanks!

Message 3 of 6
(407 Views)
Highlighted

## Re: storing and averaging value

LabVIEW relies on dataflow for the order of execution, meaning that anything that relies on data coming from upstream, has to wait until the subVIs, structures, or other nodes that provide that data are finished executing. So having a for loop in the middle of the diagram means: execute code to the left -> execute for loop N times -> execute code to the right.

(Left and right are general terms and usually how good looking code is laid out, but data can flow in any direction that you can draw a wire).

Message 4 of 6
(401 Views)
Highlighted
Solution
Accepted by topic author wew044

## Re: storing and averaging value

Here are some examples of how I might average data that is being collected in a loop.

Message 5 of 6
(398 Views)
Highlighted

## Re: storing and averaging value

Much appreciated for the explanation and example!

Message 6 of 6
(348 Views)