LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do i calculate the average of runs that have variable number of samples?

Hi
 
I am trying to calculate the average trajectory from  lets say 4 runs, with varying sample size.
 
That is, if the the 4 runs have 78,74,73,55 samples respectively, How do I calculate the average of (78+74+73+55)/4 , (78+74+73)/3 and (78+74)/2  and 78/1 ?
 
Thank you
0 Kudos
Message 1 of 9
(3,956 Views)

I'm not sure you gave a sufficient information. Assuming that you just want to calculate a linear average of the data collected in consecutive runs, you have two simple methods :

1/ concatenate the data before calculating the mean.
Simple, but can occupy a huhe amount of space since all the data have to be stored in memory

2/ store only the means Mi and the corresponding number of data points ni and calculate a balanced mean : M = sum (ni x Mi) / sum (ni) )

The attached vi illustrate both methods.

Chilly Charly    (aka CC)
0 Kudos
Message 2 of 9
(3,945 Views)

Hi

 

Thanks for your help guys.

 

I will explain a bit more.

 

Lets say i have 4 runs with the corresponding sample sizes:78 (Run 1),73(Run 2),74(Run 3),55 (Run 4). These correspond to times of 3.9,3.65,3.7 and 2.75 seconds,

 

What I want  to do  is to calculate the average profile from these runs.

 

For the first 2.75 seconds, the average is calculated by (Run 1+ Run 2 + Run 3+ Run 4)/4

The next 0.9 seconds, the average is calculated by (Run 1 + Run 2 + Run 3)/3

The next 0.5 seconds, the average is calculated by (Run 1 + Run 2)/2

and

the next 0,2 seconds the aveage is calculated by (Run 1 /1)

 

Can you please help?

 

Thank you. 

0 Kudos
Message 3 of 9
(3,926 Views)
I believed that the solution I proposed was doing exactly that. I clearly still do not understand your problem. Sorry...
Chilly Charly    (aka CC)
0 Kudos
Message 4 of 9
(3,922 Views)

Hi

 

Thanks for that.

 

But when I ran your vi, it only produced 4 points. It should produce more points than 4 (e.g. 78 points).

 

Can you please help?

 

Thank you.

 

 

0 Kudos
Message 5 of 9
(3,898 Views)

Hi again

 

I forgot to add this diagram.

Thank you.
0 Kudos
Message 6 of 9
(3,893 Views)

OK, with a picture things are easier to understand. But, please, do not use bmps ! Prefer jpegs or even better pngs, to save space and download time.

The attached vi does the job. Not optimized for large data (change the external For loop for a while loop, and do the concatenation inside...), but I had not much time...

 

Chilly Charly    (aka CC)
Message 7 of 9
(3,880 Views)

Hi

 

I made a modification to your vi (see attached). But when I run it I get the correct average but at the last point I get NaN (not an number).

I do n ot know what is going on.

 

Thank you.

 

 

0 Kudos
Message 8 of 9
(3,857 Views)
Hi Adrian,

Since you replaced the "Less?" function with a "Less Or Equal?" function, you will have to remove the "Decrement" function too. Or you could just have kept the "Less?" function in the first place.



Have fun!

Message Edited by Philip C. on 08-30-2005 11:41 PM

- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 9 of 9
(3,843 Views)