LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to average each element in an array

I have data from a Gage Card that I would like to average.  I am tuning a laser over a 50 mA range and for each 1mA increment in current, I am taking 100 scans.  Each scan consisting of about 200 points.  I cannot average more than 10 shots using the Gagecard so I would like to capture 100 scans, and average them to reduce noise.  Currently, I have my capture vi inside of a for loop which repeats 100 times and each scan writes to a file, but I would like ony 1 scan (the lower noise averaged one) per current increment.  
 
How can I average each element of 100 arrays and output this to an array?
 
Thanks for the help 
0 Kudos
Message 1 of 9
(5,116 Views)

as a clarification, I want to average the n element for each of the 100 arrays. 

 

for example, the first element of the averaged array should be the average of the first elements in each of the 100 arrays.

the second element of the averaged array should be the average of the second elements in each of the 100 arrays...

0 Kudos
Message 2 of 9
(5,108 Views)
For a 1-D array, you can do a sum of the elements and then divide by the array size.


>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 3 of 9
(5,104 Views)
Wouldn't that just give me the average of the elements in one array?
0 Kudos
Message 4 of 9
(5,086 Views)

It sounds like you want to average element 0 across 100 arrays and make that element 0 of the new averaged array.  Then average element 1 across 100 arrays and make that element 1 of the new array ...   ?????

How are you working with your 100 1-D arrays now? 

What you should do is make a 2-D array where one dimension is 100 (for the number of individual arrays) and the other dimension is how many elements are in those 100 1-D arrays.  Then you can use for loops with auto indexing to break the 2-D array down into each row or column, do the average of that array, and autoindex on the other side to build back up into the new 1-D array of averages.  You may need to to a transpose array going into your for loop in case the arrays are indexed in the wrong direction.




Message Edited by Ravens Fan on 01-21-2008 04:26 PM
0 Kudos
Message 5 of 9
(5,080 Views)

Hi Ravens Fan,

It's a new project so I haven't done much with the arrays yet.  I've been hung up on the averaging problem. 

What you describe in your first sentence is exactly what I'm trying to do and i haven't found anything straightforward using labview. 

I will try what you propose tomorrow and let you know how it goes.

 

Thanks for the help!

0 Kudos
Message 6 of 9
(5,052 Views)
I have been working with some physicists who are doing exactly what Ravens Fan described with data from a single line image "camera." I think they are doing it the way he described, but I can check if you do not get it working.

Lynn
0 Kudos
Message 7 of 9
(5,039 Views)
Ravens Fan's example is quite nice for transforming a 2-D array into the averaged 1-D array you desire. Another solution would be to use a shift register in your For Loop when you're acquiring your scans and add each scan to the previous sum. Then after the For Loop, divide the array by the number of scans you acquired. An example is shown below.




Message Edited by lion-o on 01-22-2008 01:54 PM
Message 8 of 9
(5,000 Views)
Thanks for all the help, I've got it working!
0 Kudos
Message 9 of 9
(4,969 Views)