LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

storing and averaging value

Solved!
Go to solution
Highlighted

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!

 

Download All
0 Kudos
Message 1 of 6
(461 Views)
Highlighted

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.

0 Kudos
Message 2 of 6
(451 Views)
Highlighted

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!

 

 

 

0 Kudos
Message 3 of 6
(406 Views)
Highlighted

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

0 Kudos
Message 4 of 6
(400 Views)
Highlighted
Solution
Accepted by topic author wew044

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

0 Kudos
Message 5 of 6
(397 Views)
Highlighted

Much appreciated for the explanation and example!

 

0 Kudos
Message 6 of 6
(347 Views)