如何从更大的列表中选择特定的数据列表

时间:2013-06-27 05:39:41

标签: dataset wolfram-mathematica

我有一个名为output2.txt的数据文件,它有两列数据,每个数据集用空行分隔。

在下面的代码片段中,我选择了一个介于55 -68之间的特定数据集,但我希望将整个数据集循环到文件末尾...并进行拟合

我是Mathematica的新手大约一周前开始,请在这方面提供一些意见......

SetDirectory["C:\Users\\nanosims\\Desktop\\Al_output ap_1\\Al_output \ap_1"]

B = ReadList["output2.txt", {Real, Real}]'

some = Part[B, 55 ;; 68]'

g[x_] = a + b*Exp[-c*x] + d*Exp[-e*x] + f*Exp[-h*x] + i*Exp[-j*x] /. 
FindFit[some, 
 a + b*Exp[-c*x] + d*Exp[-e*x] + f*Exp[-h*x] + i*Exp[-j*x], {a, b, 
 c, d, e, f, h, i, j}, x]'

.....

例如数据集如下:

0.000000    4866.000000
0.003400    4694.000000
0.006800    4607.000000
0.017000    4463.000000
0.027000    4404.000000
0.034000    4393.000000

0.000000    4637.000000
0.003400    4445.000000
0.006800    4343.000000
0.017000    4151.000000
0.027000    4038.000000
0.034000    3984.000000
0.068000    3881.000000

0.000000    4258.000000
0.003400    4045.000000
0.006800    3930.000000
0.017000    3706.000000
0.027000    3560.000000
0.034000    3482.000000
0.068000    3239.000000
0.170000    3028.000000

0.000000    3943.000000
0.003400    3720.000000
0.006800    3601.000000
0.017000    3363.000000
0.027000    3207.000000
0.034000    3119.000000
0.068000    2839.000000
0.170000    2482.000000
0.270000    2357.400000
0.340000    2334.900000

0.000000    3637.000000
0.003400    3411.000000
0.006800    3287.000000
0.017000    3042.000000
0.027000    2879.000000
0.034000    2789.000000
0.068000    2495.000000
0.170000    2088.500000
0.270000    1903.400000
0.340000    1822.800000
0.680000    1682.900000

0.000000    3288.000000
0.003400    3063.000000
0.006800    2936.000000
0.017000    2689.000000
0.027000    2523.000000
0.034000    2429.000000
0.068000    2128.900000
0.170000    1706.400000
0.270000    1502.200000
0.340000    1407.100000
0.680000    1160.500000
1.700000    986.000000

0.000000    3087.000000
0.003400    2860.000000
0.006800    2735.000000
0.017000    2487.000000
0.027000    2320.000000
0.034000    2228.000000
0.068000    1923.200000
0.170000    1498.000000
0.270000    1293.000000
0.340000    1196.900000
0.680000    939.600000
1.700000    696.100000
2.700000    626.900000
3.400000    615.400000

0.000000    6640.000000
0.003400    5961.000000
0.006800    5677.000000
0.017000    5248.000000
0.027000    5080.000000
0.034000    5049.000000

0.000000    6123.000000
0.003400    5395.000000
0.006800    5077.000000
0.017000    4543.000000
0.027000    4254.000000
0.034000    4119.000000
0.068000    3872.000000

0.000000    5435.000000
0.003400    4673.000000
0.006800    4335.000000
0.017000    3748.000000
0.027000    3403.000000
0.034000    3228.000000
0.068000    2735.000000
0.170000    2353.000000

0.000000    4989.000000
0.003400    4224.000000
0.006800    3876.000000
0.017000    3270.000000
0.027000    2916.000000
0.034000    2736.000000
0.068000    2206.500000
0.170000    1646.100000
0.270000    1478.300000
0.340000    1450.000000

0.000000    4645.000000
0.003400    3874.000000
0.006800    3529.000000
0.017000    2915.000000
0.027000    2557.300000
0.034000    2376.100000
0.068000    1843.900000
0.170000    1257.000000
0.270000    1038.800000
0.340000    951.800000
0.680000    812.300000

0.000000    4339.000000
0.003400    3570.000000
0.006800    3219.900000
0.017000    2617.100000
0.027000    2254.900000
0.034000    2074.200000
0.068000    1543.600000
0.170000    963.700000
0.270000    743.600000
0.340000    652.200000
0.680000    445.600000
1.700000    326.500000

0.000000    2763.000000
0.003400    2514.600000
0.006800    2375.200000
0.017000    2103.100000
0.027000    1923.500000
0.034000    1823.400000
0.068000    1500.800000
0.170000    1069.900000
0.270000    876.600000
0.340000    789.500000
0.680000    572.200000
1.700000    389.900000
2.700000    343.050000
3.400000    335.470000

0.000000    11287.000000
0.003400    8343.000000
0.006800    7511.000000
0.017000    6447.000000
0.027000    6066.000000
0.034000    5996.000000

0.000000    10311.000000
0.003400    7293.000000
0.006800    6411.000000
0.017000    5180.000000
0.027000    4590.000000
0.034000    4324.000000
0.068000    3860.900000

0.000000    9267.000000
0.003400    6213.000000
0.006800    5315.000000
0.017000    4016.200000
0.027000    3365.300000
0.034000    3057.600000
0.068000    2260.900000
0.170000    1730.800000

0.000000    8736.000000
0.003400    5686.600000
0.006800    4774.000000
0.017000    3465.400000
0.027000    2818.200000
0.034000    2512.100000
0.068000    1708.800000
0.170000    1019.600000
0.270000    848.500000
0.340000    820.300000

0.000000    8391.800000
0.003400    5332.500000
0.006800    4438.800000
0.017000    3126.800000
0.027000    2482.900000
0.034000    2182.700000
0.068000    1398.200000
0.170000    720.400000
0.270000    522.000000
0.340000    451.400000
0.680000    347.800000

0.000000    8150.600000
0.003400    5080.700000
0.006800    4176.700000
0.017000    2899.300000
0.027000    2254.900000
0.034000    1955.000000
0.068000    1186.800000
0.170000    539.900000
0.270000    352.600000
0.340000    284.700000
0.680000    153.900000
1.700000    93.450000

0.000000    8071.600000
0.003400    4984.400000
0.006800    4081.800000
0.017000    2816.200000
0.027000    2171.700000
0.034000    1873.500000
0.068000    1112.200000
0.170000    477.200000
0.270000    297.500000
0.340000    233.200000
0.680000    110.430000
1.700000    44.350000
2.700000    32.610000
3.400000    30.800000

1 个答案:

答案 0 :(得分:0)

在此处,请尝试阅读您的数据:

filedata = Function[data, data[[#[[1]] ;; #[[2]] - 2]] & /@
         Partition[Join[{1}, # + 1, 
             If[Length[data] > #[[-1]], {Length[data] + 2}, {}]] &[
                 Flatten[Position[data, {}] ]], {2}, 1]]@Import[filename, "Table"]

如果有一种不太复杂的方式,我也想知道。

说明:

导入空行时会产生空列表 {} ,因此 Position[data, {}] 会列出所有数据边界的位置。如果您在文件末尾没有双返回, If[..] 会将数据结尾添加到列表中。其余的只是在这些边界上划分数据列表。

您无需担心使用Import检测文件结尾。 Mathematica使用stream=Open[] .. Read[stream,..] .. 构造确实具有更低级别的传统编程io接口。如果你使用它,你需要检测eof,例如While[ Read[] != EndOfFile , .. ]。但在这种情况下不需要那样。