# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## creating an array/averaging question

I'm new to labview and I'm having problems understanding how to create an array.

I'm using a Arduino Uno as my DAQ and when I take an anolog measurement I've seen a lot of fuctuation in my measurement. I know with arduino you can perform simple averaging using the "Get Finite Analog Sample" function, but I know I won't be using an Arduino long term and trying to figure out the proper way to do it.

When I average with the Arduino IDE I usually have code that looks like this:

float analogsum = 0;

for(int i = 0; i < 10; i++){

analogSum += analogRead(analogPin); //where analogRead converts the analog value to a 10-bit digital value\

}

average = analogSum/10;

I'm trying to create this same function in LabView. The only way I can imagine to sum the analog value from each iteration, would be to store each value in an array, and then add them together and divide by the number of iterations in my for loop.

How would I do this in Labview?

Message 1 of 8
(3,248 Views)

## Re: creating an array/averaging question

Hi awwende,

you may use one of the "Mean" functions in the math palette.

Or you may use SumArray with a divide afterwards.

Or may use the same approach like on the Arduino by adding scalar values and dividing after the loop...

Or...

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(3,241 Views)

## Re: creating an array/averaging question

What kind of average are you trying to do?  Do you want a moving average?  Or do you just want to get 10 values and average them?

The get 10 and average is super simple.  Just put your reading of the values inside of a FOR loop.  Autoindex the values to go out of the FOR loop.  You instantly have an array of values.  Then you can just use the Mean function to get the average.  The Mean function is in the Mathematics->Probability & Statistics palette.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 8
(3,238 Views)

## Re: creating an array/averaging question

I've had a hard time understanding how data is stored in an array. All the examples I've seen have had controls on the front panel which the user inputs, I haven't come across any that will take a measurement and store it in an array and append it. And I'm also confused as to how to reset the array to start back at array[0] rather than appending to array[n+1].

Message 4 of 8
(3,235 Views)

## Re: creating an array/averaging question

It's just a simple average of 10 values.

Message 5 of 8
(3,231 Views)
Solution
Accepted by awwende

## Re: creating an array/averaging question

Hi awwende,

showing all 3 suggestions from above:

You really should go LabVIEW101 as provided on ni.com website to learn the LabVIEW basics!

Best regards,
GerdW

using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 8
(3,223 Views)

## Re: creating an array/averaging question

I did! the problem is that i start to come across something that isn't slightly different than covered in in the 101 classes and forces me to realize that I clearly don't understand visual programing as well as I think I do. Those answers help though, thanks. I didn't realize the the for loop could output an array.

Message 7 of 8
(3,219 Views)

## Re: creating an array/averaging question

Working with arrays is mainly what that loop is

*sun glasses*

For.

Really, the for loop is often used in conjunction with arrays. The auto-indexing feature of them makes them fabulous at working with arrays. If you wire a one dimensional array into them, it will automatically run the number of times that there are elements in the array taking each element in turn. And auto-indexing the output builds an array with the results of each iteration being that element of the array.

Play around and you will get the hang of it.

Good Luck,

Bob Young

Message 8 of 8
(3,143 Views)