Try using Record
and one of the options of ReadList
data = ReadList["filename", Table[Record, {7}], RecordSeparators -> {"\t", "\n"}]
Then use ToExpression
to convert the elements (since they have Head
String
) to Reals
.
ToExpression[data]
Or combine both into one line
data = ToExpression @ ReadList["filename", Table[Record, {7}], RecordSeparators -> {"\t", "\n"}]
Note that I used tabs ("\t"
) as one of my RecordSeparators
, since you haven't posted the files, so I just copied that number and created a look-alike file. You'll have to read in the first few lines of your file and use FullForm
and InputForm
to see what RecordSeparators
you should use. But this should work.
EDIT
For completeness here is how you can use InputForm
to view the structure of your file and determine what RecordSeparators
to use.
You can Read
in the first three lines of your file as follows:
ReadList["filename", String, 3]
In my made up file, here is what I get:
{" -239.916104094628030234 -239.916104094628030543 \
-239.916104094628030233", " -239.916104094628030345 \
-239.916104094628030570 -239.916104094628030355", " \
-239.916104094628030678 -239.916104094628030442 \
-239.916104094628030654"}
Then using InputForm
gives:
{" -239.916104094628030234\t -239.916104094628030543\t -239.916104094628030233",
" -239.916104094628030345\t -239.916104094628030570\t -239.916104094628030355",
" -239.916104094628030678\t -239.916104094628030442\t -239.916104094628030654"}
And you can see that "\t
" is visible.
Now using
data = ToExpression@ReadList["filename", Table[Record, {3}], RecordSeparators -> {"\t", "\n"}]
Gives:
{{-239.916104094628030234, -239.916104094628030543, -239.916104094628030233},
{-239.916104094628030345, -239.916104094628030570, -239.916104094628030355},
{-239.916104094628030678, -239.916104094628030442, -239.916104094628030654}}
Now, Head[data[[1,1]]]
gives Real
Number
instead ofReal
work? $\endgroup$Import
as alternativeReadList
? $\endgroup$