06-24-2014 03:21 PM
I have run into a snag with my code and don't know where to go ..
I am taking measurements that are being saved once to a 2d array once every 5 minutes. The data collection is going to be over the course of 72 hrs (so you can imagine the number of files). I want to save an averaged data file once an hour, which will be 12 - 2d arrays, using the same 2d array data that is saved individually each time. I know that you can create a 3d array and then average it on the 12th iteration, saving that file. I'm not entirely sure I am on the right path in trying to accomplish what I want ... but I hope I am.
I have unsuccessfully looked for existing forum posts regarding this, so if there is one, I would certainly appreciate a point in the right direction.
Thanks for the help!
06-24-2014 03:37 PM - edited 06-24-2014 04:12 PM
Why don't you simply keep summing the 2D arrays in a shift register, then divide it by the number of additions. No file IO needed.
(btw, the FOR loop in your "average" state will always produce an empty array, because the shift register is not properly initialize, Lots of your code looks really fragile)
06-26-2014 07:41 AM
Thanks for the suggestion, and taking the time to look at my issue. You said that the code looks fragile, what do you mean by that?
06-26-2014 08:27 AM
Do a Google search on "fragile code". It's an easy trap for a novice programmer to fall into, and one an experienced programmer must do their best to avoid when pressured for a "quick fix" solution.
06-26-2014 08:38 AM
thanks, but now I am on to a competely different problem ... since the "average" state wasn't finished, the test was started and is saving a new file every 5 minutes for the next 72 hrs. (thats 864 files, save ya from doing the math)
I would like to still average these files, but don't know where to start. The files names are running in sequencial order and was thinking that I could open the names into an array and then loop the data with a shift register, dividing by the number of loops? does that make sense ... or am i coming at this from the wrong angle?
06-26-2014 08:49 AM
Jared.Sweeney wrote:
I would like to still average these files, but don't know where to start. The files names are running in sequencial order and was thinking that I could open the names into an array and then loop the data with a shift register, dividing by the number of loops? does that make sense ... or am i coming at this from the wrong angle?
I would find the average of each of the files and then take the average of the average of the files. Just use a FOR loop to go through all of the files. Inside of the FOR loop, read all of the file and use the Mean.vi. Autoindex the average out of the FOR loop. Then you use the Mean.vi on the resulting array. That will help keep the array size down.