# How to write a loop to run iterations of functions to obtain different values? [closed]

I am trying to iterate the function a, b and td2 (10 times) inside a For loop. This will gives me 10 different values of td2 which eventually gives me 10 different values of fullData2. In another words, I am trying to get 10 (855 rows by 3 columns) matrix.

Hopefully, the following information can really help.

I attempted the problem using (i) for td2 and tried to iterate it in a loop. However, it didn't work (the matrix becomes {1}) .

For instance,

For[i = 1, i ⩽ 2, i++,

td2[i]

]


I would really appreciate your help.

Main Program

a = WhiteNoiseProcess[0.05];
b = RandomFunction[a, {0, 854}];
td2 = Transpose[b["ValueList"]];
columnTden2 = ConstantArray[0, {855, 2}];
noisedata2 = Join[columnTden2, td2, 2];
simdata2 = syntheticdatah2A + noisedata2;
fullData2 = simdata2
For[i = 1, i ⩽ 10, i++, list1 = td2[i]]

• Use Table, not Do. – David G. Stork Apr 19 '16 at 23:09

Just to address you For-loop problem, I start by saying don't use a For-loop for list manipulation in Mathematica. Not ever. Or at least, almost never.

The construct you want is that is closest to a For-loop, but appropriate to what you are doing is Table.

First let's generate some repeatable data.

SeedRandom; (* to insure repeatability *)
a = WhiteNoiseProcess[0.05];
b = RandomFunction[a, {0, 854}];
td2 = Transpose[b["ValueList"]];


Now consider

Table[td2[[i]], {i, 2}]


{{-0.0506024}, {0.0413169}}

But in this case it would be better to use Take.

Take[td2, 2]


or the slightly more exotic slicing syntax for arrays

 td2[[;; 2]]


Both of which give the same result as shown above.