# How to export data to a file? [closed]

Do[{T[i] = 2 Cos[(2*π*i)/60],
B[i] = 2 Cos[(2*π*i)/60 + π/3],
A[i] = 2 Cos[(2*π*i)/60 + (2 π)/3],
H[i] = 2 Cos[(2*π*i)/60 + (3 π)/3],
F[i] = 2 Cos[(2*π*i)/60 + (4 π)/3],
G[i] = 2 Cos[(2*π*i)/60 + (5 π)/3], Matt = ( {
{T[i], 1, 0, 0, 0, 1},
{1, B[i], 1, 0, 0, 0},
{0, 1, A[i], 1, 0, 0},
{0, 0, 1, H[i], 1, 0},
{0, 0, 0, 1, F[i], 1},
{1, 0, 0, 0, 1, G[i]}
} ), data[i] == Print[N[Eigenvalues[Matt]]]}, {i, 0, 9}]


I am getting $10\times 6$ values i.e. a total of 60. I want to store them in a matrix form.

Result:

{-3.09557,3.09557,-1.41421,1.41421,-0.646084,0.646084}

{-3.09468,3.09468,-1.42525,1.42525,-0.625768,0.625768}

{-3.09234,3.09234,-1.45234,1.45234,-0.572806,0.572806}

{-3.08943,3.08943,-1.48291,1.48291,-0.506382,0.506382}

{-3.08704,3.08704,-1.50577,1.50577,-0.450331,0.450331}

{-3.08613,3.08613,-1.51414,1.51414,-0.428007,0.428007}

{-3.08704,3.08704,-1.50577,1.50577,-0.450331,0.450331}

{-3.08943,3.08943,-1.48291,1.48291,-0.506382,0.506382}

{-3.09234,3.09234,-1.45234,1.45234,-0.572806,0.572806}

{-3.09468,3.09468,-1.42525,1.42525,-0.625768,0.625768}

-

## closed as off-topic by Michael E2, ciao, Yves Klett, bobthechemist, chrisJun 15 '14 at 6:47

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." – Michael E2, ciao, Yves Klett, bobthechemist, chris
If this question can be reworded to fit the rules in the help center, please edit the question.

Please post your Mathematica code instead of this Latex/Mathematica mix. –  Pickett Jun 14 '14 at 11:31
I thought, it will look cumbersome in mathematica code. –  lavkush Jun 14 '14 at 11:37
@Pickett,@Sektor, I am very thakfull to both of you. Please help me in this matter. –  lavkush Jun 14 '14 at 11:44
Still, there are missing details - Do you want to auto-export the matrix ? Are you asking how to export the matrix ? Add any relevant details to the question. –  Sektor Jun 14 '14 at 11:48
@Sektor, The result you are seeing, I want to export it in the form of row as shown in this link for example(web.cecs.pdx.edu/~gerry/MATLAB/plotting/loadingPlotData.html). Check the section for the display "Plotting data from files with column headings" –  lavkush Jun 14 '14 at 11:52

This works fine with me:

result = {};

Do[{T[i] = 2 Cos[(2*π*i)/60],
B[i] = 2 Cos[(2*π*i)/60 + π/3],
A[i] = 2 Cos[(2*π*i)/60 + (2 π)/3],
H[i] = 2 Cos[(2*π*i)/60 + (3 π)/3],
F[i] = 2 Cos[(2*π*i)/60 + (4 π)/3],
G[i] = 2 Cos[(2*π*i)/60 + (5 π)/3],
Matt = ({{T[i], 1, 0, 0, 0, 1}, {1, B[i], 1, 0, 0, 0}, {0, 1, A[i],
1, 0, 0}, {0, 0, 1, H[i], 1, 0}, {0, 0, 0, 1, F[i], 1}, {1, 0,
0, 0, 1, G[i]}}),
AppendTo[result, N[Eigenvalues[Matt]]]},
{i, 0, 9}];

Export["C:\\YourPath\\result.nb", result]

-
very thank you. If I want to save it as an txt file, because later I have to plot it. –  lavkush Jun 14 '14 at 12:18
@lavkush - in this case just replace result.nb with result.txt. For many other Export-formats read the documentation under $ExportFormats. – eldo Jun 14 '14 at 12:28 actually I wanted in the matrix form as we usually have in excel. – lavkush Jun 14 '14 at 12:30 @lavkush - then it would be result.csv :) – eldo Jun 14 '14 at 12:34 I got it through you. Thanks again. – lavkush Jun 14 '14 at 12:36 So as I understand it you want to export those values as a tab separated or space separated list so that MATLAB can read it. It shouldn't be harder than Export[path to fie, your list of lists,"TSV"];  Generally Mathematica users try to avoid using capital letters in the beginning of variables and function names because they may collide with built-in symbols. You use B, A, H, F and G. You could easily make a mistake sooner or later and try to define N, I, E or another reserved name. Matt is not ideal either for the same reason. Another thing is that Mathematica users generally try to avoid procedural operators such as Do, For, While etc. in favor of functional operators such as Map, Fold, Nest etc. because they are more efficient. This is more like how a typical Mathematica user would write your code: t[i_] := 2 Cos[(2*π*i)/60] b[i_] := 2 Cos[(2*π*i)/60 + π/3] a[i_] := 2 Cos[(2*π*i)/60 + (2 π)/3] h[i_] := 2 Cos[(2*π*i)/60 + (3 π)/3] f[i_] := 2 Cos[(2*π*i)/60 + (4 π)/3] g[i_] := 2 Cos[(2*π*i)/60 + (5 π)/3] matt[i_] := N[Eigenvalues[{ {t[i], 1, 0, 0, 0, 1}, {1, b[i], 1, 0, 0, 0}, {0, 1, a[i], 1, 0, 0}, {0, 0, 1, h[i], 1, 0}, {0, 0, 0, 1, f[i], 1}, {1, 0, 0, 0, 1, g[i]} }]] Export["~/Desktop/data.txt", Map[matt, Range[0, 9]], "TSV"]  Or even: f[i_, offset_] := 2 Cos[(2*π*i)/60 + offset π/3] matt[i_] := N[Eigenvalues[{ {f[i, 0], 1, 0, 0, 0, 1}, {1, f[i, 1], 1, 0, 0, 0}, {0, 1, f[i, 2], 1, 0, 0}, {0, 0, 1, f[i, 3], 1, 0}, {0, 0, 0, 1, f[i, 4], 1}, {1, 0, 0, 0, 1, f[i, 5]} }]] Export["~/Desktop/data.txt", Map[matt, Range[0, 9]], "TSV"]  Yet another version which you shouldn't be bothered with now, but maybe in the future you can go back and learn something from it: f[i_, offset_] := 2 Cos[(2*π*i)/60 + offset π/3] matt[i_] := N@Normal@Eigenvalues@SparseArray[{ Band[{1, 2}] -> 1, {a_, b_} /; a == b :> f[i, b], Band[{2, 1}] -> 1 }, {6, 6}] Export["~/Desktop/data.txt", Map[matt, Range[0, 9]], "TSV"]  - thank you. I will try this – lavkush Jun 14 '14 at 12:44 I got the desired result, even without using do loop. Thanks a lot. – lavkush Jun 14 '14 at 12:53 @lavkush That is the point, most people who use Mathematica don't use Do for things like this. Since I could tell you're new to Mathematica, I tried to inspire your by rewriting the code the way most Mathematica users would write it. Map does what Do would do, but they're not the same. – Pickett Jun 14 '14 at 12:57 I was trying to add a column, for the enumeration like$i\$. But I am getting. "Thread::tdlen: Objects of unequal length in {0} {0,0,0,0,0,0} cannot be combined. >>" Not able to resolve this –  lavkush Jun 14 '14 at 15:16
@lavkush I don't know what your code looks like, so I can't help you. –  Pickett Jun 14 '14 at 15:20