LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I average the values over multiple arrays?

Hi all,

 

So I have multiple text files countaining data, and I'm looking to average the data to obtain the averaged waveform - so if I have 100 very similar cosine waves, I should get something that loks like a cosine wave.

 

Attached is the VI I built to do this. The left part extracts all the data file by file and builds an array, and the left for loop computes the average. First off, is this performing the right operation? Second, it's extremely slow and this is what I'm looking to improve. I think that by running the loop as I do, I'm greatly increasing run time. Finally, I don't know how to clear the matrix everytime I stop and start the program. What it's doing now is appending the data for some reason.

 

And the reason for those smaller case structures and all that string handling is because I suited it to automatically read my files which end in something like "config1_001.txt"

 

Any advice is greatly appreciated.

 

Marc

0 Kudos
Message 1 of 5
(2,891 Views)

You are making a few mistakes.

 

  • First of all, operate with 2D arrays, not matrix data types.
  • read the files in a FOR loop, you know how many there are.
  • Simply build the 2D array at the loop boundary using an autoindexing output tunnel
  • (Actually, you can do the averaging and reading in the same loop, right?)
  • Don't write to the same file with every iteration of the loop, overwriting the old data. Once at the end is enough. 

Here's a quick draft using some simulated data... The first loop generates a 2D array of data and the second loop does the averaging. Makes sense? Also, you file reading could be dramatically simplified.

Message 2 of 5
(2,878 Views)

(ignore)

0 Kudos
Message 3 of 5
(2,848 Views)

Your VI works great, thanks!

 

I still need that file read for the way I set up my program, but it averages the data and saves it in the blink of an eye and correctly.

0 Kudos
Message 4 of 5
(2,832 Views)

You could use "list folder" with a certain pattern (e.g. config1_*.txt), then simply loop over all matching files using autoindexing.

0 Kudos
Message 5 of 5
(2,818 Views)