How to import data from a file as list/array in Mathematica

落爺英雄遲暮 提交于 2019-12-04 05:37:54

Converting Strings to Expressions is done with ToExpression. If you have a plain text file foo.txt, with the formatting as in your example, then just importing it into Mathematica with Get, i.e., << /path/to/foo.txt; will import and evaluate data in the way you want, no need for text to expression translations.

Try formatting your data file like this:

A, B, C, A, B, C, A, B, C
A, B, C, A, B, C, A, B, C
A, B, C, A, B, C, A, B, C
...

So you can use Mathematica's CSV import. Then partition each row into a list of points after import.

Partition[#, 3]& /@ Import["file.csv", "CSV"]

Also, keep in mind that Mathematica does scientific notation differently than C (or whatever language you're using to write the data file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!