# How to repeat a set of operations on a single data set?

I am very new to Mathematica and I just couldn't figure out the solution for the following problem.

I am trying to iterate the following functions for 10 times. For instance, "a" to "fullData". The function "a" and "b" will give different for every iteration. I have tried Table, for loop and nestlist but I just couldn't find the right solution. I really need some guide on this. Thanks ! I will really appreciate your help.

a = WhiteNoiseProcess[0.05];
b = RandomFunction[a, {0, 854}];
columnTden = ConstantArray[0, {855, 2}];
td2 = Transpose[b["ValueList"]];
noisedata = Join[columnTden, td2, 2];
syndatah2A = Import["/nsm/home/junhuiye/Documents/Jun/CombinedThermalMelt_h2A.csv"];
simdata1 = syndatah2A + noisedata;
fullData = simdata1;
List1 = List[fullData];

• Can you explain what "I am trying to iterate from function "a" to "fullData" for 10 times." means? This post is a little unclear. Perhaps also give a sample set of data that you are importing (since we obviously can't import it), so that we know what that data looks like. – march Apr 22 '16 at 21:11
• Hi March! Sorry about that. I just edited my question and I have also attached a sample to this post. Thanks. – justin yeoh Apr 22 '16 at 21:18
• I'm sorry, but the edits don't really make this clearer, and I don't see a set of sample data! – march Apr 22 '16 at 21:22

Unfortunately you don't provide an example of your data, but given the structure of the noise data you are generating, I am assuming that your data comes in triplets $(a,b,c)$ and that you want to add a small amount of Gaussian noise to the third column. You then want to do this ten times in a row, to generate ten different such "noisy" sets for your purposes.

Here is one way I would do that.

First of all, import your data only once at the beginning, and store it in syndatah2A. Your Import expression does this well:

syndatah2A = Import["/nsm/home/junhuiye/Documents/Jun/CombinedThermalMelt_h2A.csv"];


Secondly, since you want simple Gaussian white noise, we can draw random samples from a normal distribution with the appropriate standard deviation (RandomVariate), rather than using a WhiteNoiseProcess, which would be vastly overkill here and roughly 10x slower. Then we tack on two zeros in front to generate an array with the right shape to sum to your existing experimental data (the {0, 0, #}& /@ part).

noise := {0, 0, #} & /@ RandomVariate[NormalDistribution[0, 0.05], 855];


Notice the all-important use of SetDelayed (:=) here: this means that the value of noise will be recalculated afresh every time we use it, giving us a new set of random noise values each time, as you would want.

With this in hand, the generation of ten such noisy data sets is quite straightforward using e.g. a Table expression:

noisyData = Table[syndatah2A + noise, {10}]


Each noisy data set can be accessed using noisyData[[1]], noisyData[[2]], noisyData[[3]], etc.

Since you have not provided the data set, I have done this:

syndatah2A = Table[RandomReal[], {n, 1, 855}];


I am not sure what you are trying to do, but I assume, something like this

Funct[table_] := {
b = RandomFunction[WhiteNoiseProcess[0.05], {0, 854}];
td2 = Transpose[b["ValueList"]];
columnTden = ConstantArray[0, {855, 2}];
noisedata = Join[columnTden, td2, 2];
simdata1 = table + noisedata;
}


Then you just do the loop, something like that

For[i = 1, i <= 10, i++, Funct[syndatah2A];...]


In the loop (...) you can append it to the array, or whatever you want to do with it.