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: 

averages in an array

Hi,
 
I would like to do an average.
Now, I read some values (voltage) and I put them in an array. I read the values N times, and I add the old values with the new ones.
At the end, I divide by N all values. The average is done.
 
My problem is that I write the new values  (N) after the N-1 reading. My program did not remplace old values by the addition.
How can I specifie that I want to start to write the new values at index 0 of the array of new values.
 
Thanks fo your helping.
 
BD.
~ La programmeuse compile le C. ~
http://www.pmeonline.fr.st
http://www.nihon-fr.com
http://www.cinemasie.com
http://ippai.free.fr
0 Kudos
Message 1 of 10
(3,796 Views)
How are you building the array? What do you mean by "after the N-1 reading..". If you post your code or a picture of the block diagram it would help.
Andrew Alford
Production Test Engineering Technologist
Sustainable Energy Technologies
www.sustainableenergy.com
Message 2 of 10
(3,786 Views)
barrette_new is the array of new values
I read the element at the index i of the two array. I add this two elements, and I remplace the value of the array barrette_old with this new value.
I repeat this loop N times.
Here, the elements of barrette_new are added at the end of barretete_old, and I have, at the end of the program the N array of barrette_new in barrete_old.
 
 
Thanks,
 
BD.
 
~ La programmeuse compile le C. ~
http://www.pmeonline.fr.st
http://www.nihon-fr.com
http://www.cinemasie.com
http://ippai.free.fr
0 Kudos
Message 3 of 10
(3,779 Views)

There is no picture. If you clicked the Insert an Image button and your image was on your local pc, unless your pc is a public web site, that won't work. Use the attachment button below instead.

Instead of adding individual array elements and then doing a divide, just build the array and use the Mean function on the Analyze><athematics>Probablility and Statistics palette.

Message 4 of 10
(3,776 Views)
Sorry for this mistake 😞 I did nt see the attachement buton o_O.
 
BD.
~ La programmeuse compile le C. ~
http://www.pmeonline.fr.st
http://www.nihon-fr.com
http://www.cinemasie.com
http://ippai.free.fr
0 Kudos
Message 5 of 10
(3,771 Views)
Why are you using so many local variables? If you're going to use a for loop for anything, a shift register should be used and you should also use the auto indexing feature of a or loop instead of the Index Array functions. Every time you use a local variable, you make a copy of the data and that's not effecient.
Message 6 of 10
(3,755 Views)
Do you need to use a loop?  The arithmetic operators are polymorphic and they do take arrays as inputs.  In addition, LabVIEW includes VIs do simple things like an average (not to mention complex things like non-linear minimization).  Do a search for average and you will find a couple of options (depending on what version of LabVIEW you are using).
Message 7 of 10
(3,716 Views)

hi,

I will try your both solutions, and tell you if I resolv my problem.

tanks,

BD.

~ La programmeuse compile le C. ~
http://www.pmeonline.fr.st
http://www.nihon-fr.com
http://www.cinemasie.com
http://ippai.free.fr
0 Kudos
Message 8 of 10
(3,690 Views)

I reduce the number of local variables and I use a register shift, but it did not works, where is my mistake?

I send you the picture of my code: I would like to do an average of AVERAGES (local variable) times with a signal I acquire with DAQ card. After treatment, I got an array: BARRETTE_NEW. I add all values with an other array: BARRETTE_OLD. I do this operation AVERAGES times.

BARRETTE_NEW and BARRETTE_OLD are initialized to 0.

Did I use coorectly the shift register?
Thanks,
 
BD.
~ La programmeuse compile le C. ~
http://www.pmeonline.fr.st
http://www.nihon-fr.com
http://www.cinemasie.com
http://ippai.free.fr
0 Kudos
Message 9 of 10
(3,670 Views)

Hi, I solved my problem. Thanks very much for your helpful answers.

BD

~ La programmeuse compile le C. ~
http://www.pmeonline.fr.st
http://www.nihon-fr.com
http://www.cinemasie.com
http://ippai.free.fr
0 Kudos
Message 10 of 10
(3,656 Views)