While Export["file.txt", A, "Table"] exports a file of data, A represents a data set, in column form the question is about how to export, or print, a set of data with each data point being numbered. As an example consider the recurrence relation a[n+1]== 2*a[n]+1, a[0]=0 which yields the set of data {1, 1, 3, 7, ...}. Now if the data is exported to a file it looks like

1 1 3 7

What this question is about is how to have the data set exported to a file such that it reads:

0 1 1 1 2 3 3 7

where the first column is the n value of the recurrence relation and the second column is the corresponding data value. As an additional consideration can this two column output be applied to numerical values ? For an example consider the value of Pi calculated by N[Pi, 200]. Can the exported file have an output of the form

0 3 1 1 2 4 3 ... ?


1 Answer 1

myA = Transpose[{Range[Length[x]], x}]

Export["file.txt", myA, "Table"]

Incidentally, never use an upper-case letter or name beginning with an upper-case letter for your lists, variables or functions, to avoid potential naming conflicts with Mathematica's internal names.

myA = Transpose[{Range[200], RealDigits[N[π, 200]][[1]]}]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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