【问题标题】:How do I import a .dat file as a matrix in Mathematica?如何在 Mathematica 中将 .dat 文件作为矩阵导入?
【发布时间】:2012-12-06 15:14:05
【问题描述】:

我有一个 .dat 文件,其中包含一串数字 1 到 9,如下所示:

1

2

3

4

5

6

7

8

9

如何将数据导入mathematica,使其具有 {{1,2,3},{4,5,6},{7,8,9}} 的形式,并且可以生成 3x3 矩阵?

【问题讨论】:

    标签: file matrix wolfram-mathematica


    【解决方案1】:

    我建议:

      data=Partition[Import["<Name of data file>", "Table"],3];
    

    【讨论】:

      【解决方案2】:
      ReadList["file.dat", {Number, Number, Number}]
      
      {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
      

      也可以写成:

      ReadList["file.dat", Number ~Table~ {3}]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-27
        • 1970-01-01
        • 2014-09-12
        • 1970-01-01
        相关资源
        最近更新 更多