# How do I create a Table from a For loop?

I've been trying to create a table that has the % of the cycle of a sample and the module of acceleration for the first 100 values, but I don't know how to create it. Here's the code:

I have imported the data from an A table in excel which has the time and acceleration. There are 241 values.

Inc2 = (A[[241, 1]] - A[[1, 1]])/100 (*Percentage of my cycle*)
Reap[
For[i = 1; n = 0, i <= 100,  i++; n = n + Inc2]


Where did I go wrong?

• Welcome to the Mathematica Stack Exchange. Please load data (10 entries perhaps) and present a minimal example along with the desired outcome to get a focused reply. Thanks.
– Syed
Mar 8 at 4:39
• If you use Reap, you need Sow. And Reap need an enclosing barcket. Mar 8 at 13:47
• Do you have to use a For loop? Seems like more functional constructs can do this. Mar 8 at 14:21

Subdivide[A[[1, 1]],A[[241, 1]],100]


A bit cumbersome, but something like this might get you close to what you want without using a procedural loop.

data = RandomReal[{-1, 1}, {100, 2}];
ic2[aLast_, aFirst_] := (aLast - aFirst)/100
(ic2[#[[1]], #[[2]]] + Position[data, #][[1, 1]]) & /@ data


Probably more elegantly done with NestList or FoldList or even Table.

(I haven't had my coffee yet this morning).

1. Wolfram strongly recommends that user variable names not start with a capital letter so that those variables will not overshadow Mathematica values now or in the future.

2. I suggest reading Forman S. Acton's Real Computing Made Real to undertand why I used multiplication instead of accumulative addition. Hint: computer floating numbers almost never represent real numbers exactly,

3. Mathematica is definitely not a Fortran or C-like language

The first line generates a faked version of your code.
The second and third lines shows the first and rows of the faked data,

a = RandomReal[{0, 1}, {241, 2}];
First[a]
Last[a]
inc2 = Subtract @@ a[[{-1, 1},1]]
({#1, #1*inc2} & ) /@ Range[0, 100]
TableForm[%]


The matching results"

{0.10746548833059077, 0.08695916608169596}
{0.6458285821946712, 0.3832483598318581}
0.5383630938640804
{{0, 0.}, {1, 0.5383630938640804}, {2, 1.0767261877281609},
{3, 1.6150892815922413}, {4, 2.1534523754563217},
{5, 2.691815469320402}, {6, 3.2301785631844826},
{7, 3.768541657048563}, {8, 4.3069047509126435},
{9, 4.845267844776724}, {10, 5.383630938640804},
{11, 5.921994032504885}, {12, 6.460357126368965},
{13, 6.998720220233046}, {14, 7.537083314097126},
{15, 8.075446407961206}, {16, 8.613809501825287},
{17, 9.152172595689368}, {18, 9.690535689553448},
{19, 10.228898783417527}, {20, 10.767261877281609},
{21, 11.30562497114569}, {22, 11.84398806500977},
{23, 12.382351158873849}, {24, 12.92071425273793},
{25, 13.459077346602012}, {26, 13.997440440466091},
{27, 14.53580353433017}, {28, 15.074166628194252},
{29, 15.612529722058333}, {30, 16.15089281592241},
{31, 16.689255909786493}, {32, 17.227619003650574},
{33, 17.765982097514655}, {34, 18.304345191378737},
{35, 18.842708285242814}, {36, 19.381071379106896},
{37, 19.919434472970977}, {38, 20.457797566835055},
{39, 20.996160660699136}, {40, 21.534523754563217},
{41, 22.0728868484273}, {42, 22.61124994229138},
{43, 23.149613036155458}, {44, 23.68797613001954},
{45, 24.22633922388362}, {46, 24.764702317747698},
{47, 25.30306541161178}, {48, 25.84142850547586},
{49, 26.379791599339942}, {50, 26.918154693204023},
{51, 27.4565177870681}, {52, 27.994880880932183},
{53, 28.533243974796264}, {54, 29.07160706866034},
{55, 29.609970162524423}, {56, 30.148333256388504},
{57, 30.686696350252586}, {58, 31.225059444116667},
{59, 31.763422537980745}, {60, 32.30178563184482},
{61, 32.84014872570891}, {62, 33.378511819572985},
{63, 33.91687491343707}, {64, 34.45523800730115},
{65, 34.993601101165225}, {66, 35.53196419502931},
{67, 36.07032728889339}, {68, 36.60869038275747},
{69, 37.14705347662155}, {70, 37.68541657048563},
{71, 38.22377966434971}, {72, 38.76214275821379},
{73, 39.30050585207787}, {74, 39.838868945941954},
{75, 40.37723203980603}, {76, 40.91559513367011},
{77, 41.453958227534194}, {78, 41.99232132139827},
{79, 42.53068441526236}, {80, 43.069047509126435},
{81, 43.60741060299051}, {82, 44.1457736968546},
{83, 44.684136790718675}, {84, 45.22249988458276},
{85, 45.76086297844684}, {86, 46.299226072310915},
{87, 46.837589166175}, {88, 47.37595226003908},
{89, 47.914315353903156}, {90, 48.45267844776724},
{91, 48.99104154163132}, {92, 49.529404635495396},
{93, 50.06776772935948}, {94, 50.60613082322356},
{95, 51.144493917087644}, {96, 51.68285701095172},
{97, 52.2212201048158}, {98, 52.759583198679884},
{99, 53.29794629254396}, {100, 53.83630938640805}}
TableForm[{{0, 0.}, {1, 0.5383630938640804},
{2, 1.0767261877281609}, {3, 1.6150892815922413},
{4, 2.1534523754563217}, {5, 2.691815469320402},
{6, 3.2301785631844826}, {7, 3.768541657048563},
{8, 4.3069047509126435}, {9, 4.845267844776724},
{10, 5.383630938640804}, {11, 5.921994032504885},
{12, 6.460357126368965}, {13, 6.998720220233046},
{14, 7.537083314097126}, {15, 8.075446407961206},
{16, 8.613809501825287}, {17, 9.152172595689368},
{18, 9.690535689553448}, {19, 10.228898783417527},
{20, 10.767261877281609}, {21, 11.30562497114569},
{22, 11.84398806500977}, {23, 12.382351158873849},
{24, 12.92071425273793}, {25, 13.459077346602012},
{26, 13.997440440466091}, {27, 14.53580353433017},
{28, 15.074166628194252}, {29, 15.612529722058333},
{30, 16.15089281592241}, {31, 16.689255909786493},
{32, 17.227619003650574}, {33, 17.765982097514655},
{34, 18.304345191378737}, {35, 18.842708285242814},
{36, 19.381071379106896}, {37, 19.919434472970977},
{38, 20.457797566835055}, {39, 20.996160660699136},
{40, 21.534523754563217}, {41, 22.0728868484273},
{42, 22.61124994229138}, {43, 23.149613036155458},
{44, 23.68797613001954}, {45, 24.22633922388362},
{46, 24.764702317747698}, {47, 25.30306541161178},
{48, 25.84142850547586}, {49, 26.379791599339942},
{50, 26.918154693204023}, {51, 27.4565177870681},
{52, 27.994880880932183}, {53, 28.533243974796264},
{54, 29.07160706866034}, {55, 29.609970162524423},
{56, 30.148333256388504}, {57, 30.686696350252586},
{58, 31.225059444116667}, {59, 31.763422537980745},
{60, 32.30178563184482}, {61, 32.84014872570891},
{62, 33.378511819572985}, {63, 33.91687491343707},
{64, 34.45523800730115}, {65, 34.993601101165225},
{66, 35.53196419502931}, {67, 36.07032728889339},
{68, 36.60869038275747}, {69, 37.14705347662155},
{70, 37.68541657048563}, {71, 38.22377966434971},
{72, 38.76214275821379}, {73, 39.30050585207787},
{74, 39.838868945941954}, {75, 40.37723203980603},
{76, 40.91559513367011}, {77, 41.453958227534194},
{78, 41.99232132139827}, {79, 42.53068441526236},
{80, 43.069047509126435}, {81, 43.60741060299051},
{82, 44.1457736968546}, {83, 44.684136790718675},
{84, 45.22249988458276}, {85, 45.76086297844684},
{86, 46.299226072310915}, {87, 46.837589166175},
{88, 47.37595226003908}, {89, 47.914315353903156},
{90, 48.45267844776724}, {91, 48.99104154163132},
{92, 49.529404635495396}, {93, 50.06776772935948},
{94, 50.60613082322356}, {95, 51.144493917087644},
{96, 51.68285701095172}, {97, 52.2212201048158},
{98, 52.759583198679884}, {99, 53.29794629254396},
{100, 53.83630938640805}}]