Message Boards Message Boards

GROUPS:

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

Posted 1 year ago
1890 Views
|
5 Replies
|
4 Total Likes
|

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"): enter image description here

Any input appreciated! //Mike

Attachments:
5 Replies

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]];
Posted 1 year ago

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.

Attachments:
Posted 1 year ago

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

Thanks!

//Mike

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract