キャンセル
次の結果を表示 
次の代わりに検索 
もしかして: 

For loop to get average

How can I use a for loop to get average of set of values?
For example, if I have samples going into the for loop of ten iterations,and end of each ten iterartions I need to calculate the average.
Thanks.
0 件の賞賛
メッセージ1/28
6,159件の閲覧回数
Hi,
 
Average (arithm) = sum of the elements / number of elements. Do that in the loop. What is the problem? 
Use  a shift register to pass the data from the previous iteration and a build array to append the data.
you'll get the average with the Mean.vi (Analyse=>Math=>Prob and Stats). Be aware that using the build array
function will use much more memory than initialising the shift register and using replace array subset.
But there, you'd need to calculate the number of elements and use array subset before averaging.
 
Dai
Dai

LV 7.1 - WIN XP - RT - FP
0 件の賞賛
メッセージ2/28
6,150件の閲覧回数

Hi,

There are several ways to do an average.

There is a function in analyse - mathematics - probability and statistics - mean.vi that averages an array of values.

You could also add all the 10 values and then divide by 10.

Take a look at the attached vi,

Hope it helps,

Paulo 

メッセージ3/28
6,148件の閲覧回数
Hello,

one possible way is also:
sum up all elements with "Add Array Elements" function and divide by "array size". This way you dont need a for loop. But using "Mean.vi" or "Std Deviation and variance" from the probability palette is still more elegant...


Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 件の賞賛
メッセージ4/28
6,140件の閲覧回数
Thanks for the replies.
Please explain me how to get the average of 100 results samples of attached vi and display them in the text box out side the loop or collect them into an array. I need to store a value for each 100 samples.
Thanks.
0 件の賞賛
メッセージ5/28
6,134件の閲覧回数
メッセージ6/28
6,024件の閲覧回数
Hello Ravi,

maybe this will help you.
Remember that "Average of 100 elements" and "mean" are no 'text boxes' but numeric indicators...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 件の賞賛
メッセージ7/28
6,000件の閲覧回数

Gerd,

I tried to display the values in a table as in the attached file. Do you have any idea why I get a value for only the first one?There should be a value for each sapling point before averaging.

Next thing is, my original signal is from a while loop, where each iteration of the while loop, I can send a block of samples (say 100) to this vi. So, I need to get series of average values (one each for each 100 samples) and save them in another array.

Can you help me please?

Thanks,

Ravi.

0 件の賞賛
メッセージ8/28
5,982件の閲覧回数
Hello Ravi,

this should help 🙂


Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
メッセージ9/28
5,969件の閲覧回数

Hi Gerd,

That helped me lot! I learned so much from your answers.

Thanks a lot again!

Ravi.

0 件の賞賛
メッセージ10/28
5,948件の閲覧回数