mathematica读入txt文件的问题
读入txt文件的问题
现有一个txt文件,4列,113496行,形如:
0 0 0 0
0.000264326 0 0 0
0.000528653 0 0 0
3.22558 0 0 1.4822e-323
0.00105731 0 0 14.0000
0.00132163 0 0 0
0.00158596 0 0 0
0.00185029 0 0 0
0.00211461 0 0 0
......
数字中间用Tab隔开,现在我想把这个文件读入到TABLE中,为了后期的处理,比如用第一列和第三列做图,等等处理,我适用了如下代码:
SetDirectory[NotebookDirectory[]];
file = Import["./root/field8um.txt", "Data"];
data = ReadList[file, {Real, Real, Real, Real}]
Colse[file];
但提示Failed,,,请问这是什么问题呢?
0 0 0 0
0.000264326 0 0 0
0.000528653 0 0 0
3.22558 0 0 1.4822e-323
0.00105731 0 0 14.0000
0.00132163 0 0 0
0.00158596 0 0 0
0.00185029 0 0 0
0.00211461 0 0 0
......
数字中间用Tab隔开,现在我想把这个文件读入到TABLE中,为了后期的处理,比如用第一列和第三列做图,等等处理,我适用了如下代码:
SetDirectory[NotebookDirectory[]];
file = Import["./root/field8um.txt", "Data"];
data = ReadList[file, {Real, Real, Real, Real}]
Colse[file];
但提示Failed,,,请问这是什么问题呢?
直接data = Import["C:\\Users\\ChenyuLue\\Documents\\data.txt", "Table"]不就行了?
输出结果:{{0, 0, 0, 0}, {0.005, 0, 0, 0}, {3.224, 0, 0, 1.480000000000000*10^-323}}
然后你随便你取列取行了
输出结果:{{0, 0, 0, 0}, {0.005, 0, 0, 0}, {3.224, 0, 0, 1.480000000000000*10^-323}}
然后你随便你取列取行了
- situxuming: 回复 liuqc0409 :比如取出取出第三列,ListLinePlot[data[[All,3]]] data[[All,i]]表示取出第i列,data[[i]]表示取出第i行,data[[i,j]]表示取出第i行第j列元素2012-11-30 14:06回复
SetDirectory[NotebookDirectory[]];
data = Import["./root/field8um.txt", "Table"];
ListPlot[Table[{data[[i, 1]], data[[i, 3]]}, {i, 1, 113496}], Joined -> True, PlotRange -> {{0, 30}, {-30, 30}}]
接下来试试MMA9的滤波功能了。。。
data = Import["./root/field8um.txt", "Table"];
ListPlot[Table[{data[[i, 1]], data[[i, 3]]}, {i, 1, 113496}], Joined -> True, PlotRange -> {{0, 30}, {-30, 30}}]
接下来试试MMA9的滤波功能了。。。
————————————————————————————————————————————————
mathematica中如何把For循环产生的三维维数据导出到txt文件中
用Export就行了。示例:
Table[i j k, {i, 1, 5}, {j, 1, 5}, {k, 1, 5}]
Export["shuzu.txt", %]
这样就把用Table产生的这个三维数组弄到shuzu.txt里面了。至于保存的路径嘛,用Directory指令:
Directory[]
要改储存路径的话就先执行SetDirectory,比如:
SetDirectory["D:\\文字"]
这样就把路径改到D盘的文字路径下面了。