LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate the average value

Solved!
Go to solution

the data I measured changed rapidly, so i want get the average value of the data

 

Do not tell me to use mean.vi , i have already know that.

 

and i got an idea which is add the data into an array every time, then sum of all the data value and take the result divide by the number of elements

 

but i dont know how to achieve that, anyone can build a simple vi to show me ? thank you

 

i have attached my vi which is using mean.vi to calc the average value, you can delete it and using in your way ,  thank you !

0 Kudos
Message 1 of 7
(9,832 Views)
Solution
Accepted by LeoLiu

Don't add your data to an array that grows forever. What a waste of RAM. To calculate the mean, you only need the sum and N.

 

Here's a simple code to accumulate the sum of values in a shift register and divide by the number of add operations.

 

 

Message 2 of 7
(9,823 Views)

Hi , i got another question

 

when i put the new vi into my circuit, the whole circuit stoped, can you help to figure this out?

 

 

0 Kudos
Message 3 of 7
(9,806 Views)

You did not include the subVI, but I guess the subVI has a while loop that does not stop, so control will not return to the main VI.

 

Maybe you want to place the shift register in the main loop of the toplevel VI instead.

0 Kudos
Message 4 of 7
(9,796 Views)

sorry, forgot to attached the sub-vi

So how to make the while loop stop.

Because the circuit is continuously receiving data and it is constantly calculating the average, if it stopped, it can not calculate the average, isn't it?

0 Kudos
Message 5 of 7
(9,774 Views)

Well, you can make he while loop stop by wiring a false constant to the termination condition. Still, you are completely missing the point. Think dataflow!

 

If you want to use this as a subVI, you need to keep track of both the sum and the number of entries, so you need two shift registers or feedback nodes. A globally initialized feedback node is preferred, because ti does not need a while loop and "first run?" logic, etc. You also need to make the subVI re-entrant, so each instance keeps it's own history.

 

Here is a quick example, try it!

Message 6 of 7
(9,750 Views)

Hi I got a similar issue for averaging. I used the mean.vi from the math function but the average is rolling when i run it. I am trying to calculate the average for the data i read to the RT FIFO (which is around 40000 lines).I got the writing part working, however, when i am reading the data, I couldn't get it working. I thought i read the data as a 1-D array, and then pass it to the Mean.vi and then got the result. But seems like the mean is only showing the last data in the array.

 

Can someone help me with this??

 

 

Download All
0 Kudos
Message 7 of 7
(9,433 Views)