2

I have a .dat file consisting of a string of numbers 1 to 9 that looks like this:

1

2

3

4

5

6

7

8

9

How do I import the data into mathematica so that it has the form {{1,2,3},{4,5,6},{7,8,9}} and I can generate my 3x3 matrix?

4

2 回答 2

2

我建议:

  data=Partition[Import["<Name of data file>", "Table"],3];
于 2012-12-06T15:39:34.157 回答
0
ReadList["file.dat", {Number, Number, Number}]
{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}

也可以写成:

ReadList["file.dat", Number ~Table~ {3}]
于 2012-12-08T12:34:00.510 回答