LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Please help in calculating average from random nos. generated

Actually i am new to LV and i don't understand e'thing pretty well. Can anyone please help me with this problem?

I have to construct a VI that displays a random no. once every sec., and then in the same VI, i am trying to compute the average of the last four nos. generated, i.e. the average is displayed only after 4 numbers have been generated, else the average displays zero.

Well, i was trying to  get this, but so far what i have got is a VI that is generating average, but that is not what i need.

Thanks for any help.

CL

0 Kudos
Message 1 of 7
(3,136 Views)

Hi

Could you post your vi? If you're new to LV, it is better to advise you on the work you've already done, than just give you a solution.

Why do you want to display zero until you have 4 elements? Is there a reason for that?

Thomas

 

Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 2 of 7
(3,131 Views)

hi,

 

there is no reason in particular ro display 0,  just set it up like that. I have worked on a VI that just computes the running avg. Here it is.

 

Thanks,

CL

0 Kudos
Message 3 of 7
(3,127 Views)
Hello Charu,

have a look at my attachment. I changed your example to your needs (hopefully).

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 7
(3,119 Views)

Easiest would be to use "Mean PtByPt.vi" in the Analyze...Point by Point palette. It is most flexible, e.g. if you would want to change the averaging length in the future.

Alternatively, you could use shift registers initialized with NaN. I would prefer NaN over zero for incomplete samples, zero is not unique, it could be a legal value. See attached simple example (LabVIEW 7.1). Modify as needed.

0 Kudos
Message 5 of 7
(3,107 Views)
Hello Charu,

there's a small error in my example: please change the comparison to "greater than 2" or "greater/equal than 3".
And to initialize with NaN instead of zero (see Altenbach below) is also a good idea!



Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 7
(3,105 Views)

Thanks all, for your kind help.

CL.

0 Kudos
Message 7 of 7
(3,102 Views)