[Solved] Loop a fourier calculation and export to csv-file

I want to evaluate the code below for a series of s, running s from for example 1 to 100, or with s being a list of specific numbers in a list such as {5,7,10, etc}. The result for each evaluation, thus for each individual s in the series, should be exported into a separate column in a csv file. In the attached notebook, as you see, I have set s to 5, thus exporting the resulting cosine projected 5000 steps into a single column csv.
So far I have found the command Do:
Do[sums, {s, list}] or Do[sums, {s, 100}], but then I have trouble incorporating the successive export for each s calculated.

The code/setup (also attached as a notebook file “test loop atco”):

Any input appreciated!
//Mike

test loop atco.nb (66.4 KB)

Hi Mike,
My approach: prior to the calculations, create a two dimensional empty table:

results = Table[Table[{}, columns], rows];

then after filling it with data, export it to a file name ending in .csv

Export[somePath <> "myresults.csv", results];

If you want a header row in your file:

resultsHeader = {col1label, ... };
Export[somePath <> "myresults.csv", Join[{resultsHeader}, results]];

Much appreciated! Perhaps your idea could be combined with the “Do” command to get the loop sorted but still seems uncertain to me how I implement that each s gets its own column until all calcs are done.

Or … you could do the columns one at at time, knowing which column the current s belongs to.

Hi alltimetrader

There is no need to create an empty Table and fill it using Do or some other looping construct. One way to deal with your problem is to encapsulate the generation of sums for a specific value of s and steps in a function. Then call the function in a Table to generate the desired output.

I modified your notebook and added the proposed solution in the attached “test loop atco v2.nb”. The changes are at the end. No existing code was modified.

test loop atco v2.nb (14.2 KB)

Wow Rohit. You made my day. Much obliged. Much to be learned..

Thanks!

//Mike