According to your code, what you are saving is an array of means (one from each iteration), and NOT the last iteration. If you want to keep the entire data, it would be a 2D array.
Why are you generating an entire waveform at each iteration? Shouldn't you just generate one point?