Message Boards Message Boards

0
|
4990 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

how to export and import table with fixed accuracy

Dear all.

I want to export a table (3 columns) with a fixed number of digits (accuracy). So the numbers (complex) should have 100 digits and the number format should be like e.g. 1.32448754E-43+234454E-23*I. I tried to use Export[“M.out”,x,”Table”]. The export works fine, but when importing the Table cannot be used in ListLinePlot. I really struggle to get that work, any ideas?

Thanks in advance for your help,

Markus

POSTED BY: Markus Schmidt

It depends when you encounter the problem, You cannot plot complex data, so a + I *b need to be transformed to {a,b} before calling to ListPlot. You can do that using ReplaceAll

so

tab=RandomComplex[{-0.01 - 0.01 I, 0.01 + 0.02 I}/10000, 100]; ListPlot[tab /. Complex[x, y] :> List[x, y]]

If your problem appears AFTER importing back the data, you need to notice that the data is imported as strings and you need to use ToExpression to overcome that

exp = Export["~/table.txt", tab, "Table"];

imp=Import[["~/table.txt", "Table"];

Dimensions[tab] returns 100

Dimensions[imp] returns {100,1} so there is a surrounding List that you can cancel using Flatten

so for this part

ListPlot[Flatten[(ToExpression@Import["~/table.txt", "Table"])] /. Complex[x, y] :> {x, y}]

will do the trick HTH yehuda

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