1
$\begingroup$

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]]
$\endgroup$

closed as off-topic by m_goldberg, MarcoB, RunnyKine, user9660, Alexey Popkov Apr 20 '16 at 12:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – m_goldberg, MarcoB, RunnyKine, Community, Alexey Popkov
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ You will the help you asking for by reading this question and its answers. $\endgroup$ – m_goldberg Apr 19 '16 at 22:36
  • $\begingroup$ Use Table, not Do. $\endgroup$ – David G. Stork Apr 19 '16 at 23:09
2
$\begingroup$

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[42]; (* 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.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.