Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have an array which is defined as a table, e.g.

g = Table[ cos[l1*3.]*sqrt[l2*1.]*l3 + l1*1 , {l1, 0, 3}, {l2, 0, 3}, {l3, 0, 3}];

then, I need to save it in the following format

1 1 1 g[1,1,1]


i1 i2 i3 g[i1,i2,i3]

If I do something like

Do[ Export[ file, {i, g[[i, 2, 3]]}], {i, 1, 4}];

then it saves only the last line for i == 4:

3 + 2*cos[9.]*sqrt[1.]

Another "subquestion" - is there a way to convert the Table to float? N doesn't help.

share|improve this question

closed as off-topic by Yves Klett, Artes, m_goldberg, Sjoerd C. de Vries, rm -rf Oct 18 '13 at 2:39

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." – Yves Klett, Artes, m_goldberg, Sjoerd C. de Vries, rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

Please do format your post properly and look at some basic tutorials first. –  Yves Klett Oct 17 '13 at 16:27
cos and sqrt need an Uppercase first character like every built-in Mathematica function. –  Sjoerd C. de Vries Oct 17 '13 at 21:40
Answer to your subquestion: Mathematica is case-sensitive so cos is not the same as Cos. Please do familiarise yourself with the the basic tutorials in the documentation, as this will save you and other site members a lot of time. –  Verbeia Oct 17 '13 at 22:03

1 Answer 1

g = Table[{l1, l2, l3, Cos[l1*3.]*Sqrt[l2*1.]*l3 + l1*1}, {l1, 0, 3}, {l2, 0, 3}, {l3, 0, 3}];
Export["test.txt", g]

will store the whole table at once in the file. Read it back in with

g = Import["test.txt"]

You may find it helpful to look at the help files for Import and Export for other options.

share|improve this answer
You are a kind and patient person. –  Yves Klett Oct 17 '13 at 16:33
@Yves Klett --- "the trick is sincerity: if you can fake that, you've got it made." –  bill s Oct 17 '13 at 16:45
I could not fake any enthusiasm for this Q, but I am humbled (+1). –  Yves Klett Oct 17 '13 at 16:49

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