ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate mean in while loop

I wrote the attached labview program to calculate the reaction time to a stimulus (red/green light simulating a traffic light). The program will be used for driver rehabilitation to determine whether a person can drive by putting their reaction time into percentiles based on gender and age (the part of the program outside of the while loop).

I have the program set to record the reaction time from the red stimulus to the depression of a switch. The problem is calculating the mean reaction time.

I need to temporarily store each value in the case structure inside of the while loop (the values storing to the table on the front panel). I then need to calculate the mean. The "mean" subvi is only displaying the last value. I understand that this portion probably resets after each iteration, but how do I set it to keep the values I need stored and calculate the new average each time the loop runs.

So, I need the average to display after each iteration, I guess a moving average?.

Any help will be GREATLY APPRECIATED!! :0)
0 Kudos
Message 1 of 9
(5,909 Views)
0 Kudos
Message 2 of 9
(5,908 Views)

You can use a shift register to keep the previous values of the array and use insert into array to add the latest value. See pic for more info.

Hope it helps !

 



Message Edited by Deepu on 04-30-2008 12:58 PM
0 Kudos
Message 3 of 9
(5,895 Views)
The point-by-point VIs are perfect for this use.
You can feed it every time a new value and it will calculate it's mean after every run.

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 4 of 9
(5,875 Views)
I tried to edit the program by inserting the shift register. What is the input to the loop, the box with the constant "zero." I can't find an array constant that looks like that one on the functions palette. Thanks!
0 Kudos
Message 5 of 9
(5,839 Views)

It is an array constant.  You need to place an array container on your block diagram.  Then place a numeric constant with a double representation.  Then drag the numeric constant into the array container to turn it into an array constant.  It will actually be an empty array with double representation.

It sounds like you are very new to LabVIEW as this is actually pretty basic LabVIEW knowledge.  I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours
Message 6 of 9
(5,834 Views)

If you want to create an array constant quickly for your shift register initial value input, then right click on the wire which is connected to the input of the Mean vi, and select Create -> Constant. Drag this out side the loop beside the shift register and connect it to the shift register.

0 Kudos
Message 7 of 9
(5,819 Views)
Thanks for all of your help!! I got the program working correctly last night. I am new to LabVIEW, and this program has been a work in progress for quite some time. I did learn a lot though!! :0) Thanks again, I really appreciate your help!!!! Now I can graduate! :0)
0 Kudos
Message 8 of 9
(5,785 Views)

Good to know that u can solve the problem...

But never forget to rate a good answer... Smiley Wink

0 Kudos
Message 9 of 9
(5,759 Views)